Move the mouse left and right to change the complexity level of the cardioid. Press any key to save image.
A fork of Cardioid by Athena Nie
xxxxxxxxxx
p5.disableFriendlyErrors = true;
let n = 16;
let tau = 6.28319;
let i;
let m = 0;
function setup() {
createCanvas(1112,834);
colorMode(HSB, 255);
background(255);
mouseX = width / 2;
mouseY = height / 2;
}
function draw() {
translate(100, -10);
scale(1.5);
let x = [100];
let y = [100];
let r = [100];
let t = [100];
n = 3 + mouseX * 47/600;
for (i=0; i<n; i++) {
t[i] = tau/4 + i*tau/n;
}
for (i=0; i<n; i++) {
x[i] = 300 + 100 * cos(t[i]);
y[i] = 200 - 100 * sin(t[i]);
}
for (i=0; i<n; i++) {
r[i] = sqrt((300 - x[i])*(300 - x[i]) + (100 - y[i])*(100 - y[i]));
}
background(255);
noFill();
for (i=0; i<100; i++) {
stroke((m+i*5)%255, 255, 255);
ellipse(x[i], y[i], 2*r[i], 2*r[i]);
}
m++;
}
function keyPressed(){
save('pix.jpg');
}