自定义函数未实现

Custom function not implementing

我尝试制作自己的函数,在我选择的特定坐标中绘制心形动画,但出于某种原因,当我尝试实现它时,它没有显示在 canvas 上。我知道我在某个地方做了一些非常错误的事情,但我无法全神贯注。

let points = [];
let a = 0;

function setup() {
  createCanvas(928,500);
}

function draw() {
  background(0);
  heart(200, 200, 10);
}

function heart(x, y, r) {
  r = r;
  x = x + (r * 16 * pow(sin(a), 3));
  y = y + (-r * (13 * cos(a) - 5 * cos(2 * a) - 2 * cos(3 * a) - cos(4 * a)));
  
  beginShape();
  points.forEach(point => {
    vertex(point.x, point.y);
  })
  endShape();

  points.push(x, y);
  a += 0.05
}

已修复,非常好,做得好。我不知道 'a' 的限制,所以我可能会无缘无故地循环。

    function heart(X, Y, r) {
    translate(X,Y);
  
    
    beginShape();
    for(a = 0; a < 10; a += 0.05){
        let x = (r * 16 * pow(sin(a), 3));
    let y = (-r * (13 * cos(a) - 5 * cos(2 * a) - 2 * cos(3 * a) - cos(4 * a)));
        vertex(x,y);
    }
    endShape();}

这就是你想要的自画像吗?

function setup() {
  createCanvas(928,500);
}

function draw() {
  background(0);
  heart(200, 200, 10, frameCount / 200); //the last value is how much of the heart is made, you can change by how much it is divided to alter the speed
}

function heart(X, Y, r, limit) {
translate(X,Y);


beginShape();
for(a = 0; a < limit; a += 0.01){
    let x = (r * 16 * pow(sin(a), 3));
let y = (-r * (13 * cos(a) - 5 * cos(2 * a) - 2 * cos(3 * a) - cos(4 * a)));
    vertex(x,y);
}
endShape();}