xxxxxxxxxx
45
let npoints = 100;
let radius;
let percent = 0;
function setup() {
createCanvas(400, 400);
radius = width / 2 - 16;
}
function draw() {
background(0);
push();
translate(width / 2, height / 2);
var angle = TWO_PI / npoints;
fill(150,0,100);
stroke(255);
strokeWeight(4);
beginShape();
for (var a = 0; a < TWO_PI; a += angle) {
// cardioid
let ac = a;
let r = (1 - sin(ac)) * 0.66;
let cx = cos(ac) * r * radius;
let cy = ((sin(ac) * r) + 0.5) * radius;
// heart 1
let ah = PI / 2 - a;
let hx = 16 * pow(sin(ah), 3) * radius * 0.05;
let hy = (13 * cos(ah) - 5 * cos( 2 * ah) - 2 * cos(3 * ah) - cos(4 * ah)) * radius * 0.05;
let coef = sin(percent * PI);
let sx = cx * coef + hx * (1 - coef);
let sy = cy * coef + hy * (1 - coef);
vertex(sx, -sy);
}
endShape(CLOSE);
pop();
percent += 0.02;
if (percent >= 1)
{
percent = 0;
}
}