/**
* @description: 心形
* @param {number} ax 宽度
* @param {number} ay 高度
* @param {number} len 点数量
*/
function love(ax: number, ay: number, len: number) {
len = len < 80 ? 80 : len
const arr = []
for (let i = 0; i < len; i++) {
const step = (i / len) * (Math.PI * 2) //递增的θ
const vector = {
x: ax * (18 * Math.pow(Math.sin(step), 3)),
y:
-ay *
(13 * Math.cos(step) -
5 * Math.cos(2 * step) -
2 * Math.cos(3 * step) -
Math.cos(4 * step))
}
arr.push(vector)
}
return arr
}
调用
love(width / 36, (height + height * 0.22) / 36, width * 20)