let c = [];
function setup() {
s = min(windowWidth, windowHeight);
createCanvas(s * 0.9, s * 0.9);
c[0] = [];
c[1] = [];
trefoil();
}
function draw() {
t = frameCount / 100;
background(255 * cos(t / 3));
translate(width / 2, height / 2);
for (let i = 0; i < int(width / 10); i++) {
stroke(10 + i * 9 * abs(sin(t / 10)));
strokeWeight(0.1);
plotT(i + (width / 4) * sin(t / 2));
}
}
function trefoil() {
for (let i = 0; i < TWO_PI * 70; i++) {
c[0][i] = sin(i) + 2 * sin(2 * i);
c[1][i] = cos(i) - 2 * cos(2 * i);
}
}
function plotT(r) {
noFill();
beginShape();
for (let i = 0; i < c[0].length; i++) {
vertex(r * c[0][i], r * c[1][i]);
}
endShape(CLOSE);
}