第一种方法:桃心形公式
代码实现的一种方法
使用桃心形方程绘制爱心var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var Heart = function(ctx, x, y, a) {
this.ctx = ctx;
this.x = x;
this.y = y;
this.a = a;
this.vertices = [];
for(let i=0; i<50; i++) {
var step = i/50*(Math.PI*2);//设置心上面两点之间的角度,具体分成多少份,好像需要去试。
var vector = {
x : this.a*(16 * Math.pow(Math.sin(step), 3)),
y : this.a*(13 * Math.cos(step) - 5 * Math.cos(2 * step) - 2 * Math.cos(3 * step) - Math.cos(4 * st