xxxxxxxxxx
54
const magic = 0.552284749831;
function setup() {
createCanvas(512, 512);
}
// Draw a shape that interpolates between a circle
// and a square.
function thingy(squareness) {
const m = lerp(magic, 0, squareness);
beginShape();
vertex(1, 0);
bezierVertex(1, m, m, 1, 0, 1);
bezierVertex(-m, 1, -1, m, -1, 0);
bezierVertex(-1, -m, -m, -1, 0, -1);
bezierVertex(m, -1, 1, -m, 1, 0);
endShape(CLOSE);
}
function draw() {
background(255);
noStroke();
push();
translate(width / 2, height / 2);
rotate(QUARTER_PI);
const period = 50;
let t = map(frameCount % 200, 0, 2 * period, 0, 2 * period);
r = width / 2 + 3 * period + t;
let b = true;
while (r > 0) {
push();
scale(r);
if (b) {
fill(80, 80, 100);
} else {
fill(250, 250, 230);
}
thingy(map(r, 0, 0.7 * width, 0, 1));
pop();
b = 1 - b;
r = r - period;
}
pop();
}
function keyPressed() {
if (key == "g") {
saveGif("output", 200, { units: "frames", delay: 0 });
}
}