p5.js
Iris
Nested rings tilting in a slow 3D wave, morphing from diamond to circle. A 2024 p5.js piece.
Licence: CC BY-NC-SA 4.0: remix with credit, non-commercial, share alike
View the code
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
}
function draw() {
background(0);
const t = millis() / 1000;
const S = min(width, height);
const n = floor(params.rings);
const detail = 160;
const fov = map(params.perspective, 0, 2, 0.05, 1.4);
perspective(fov, width / height, 1, 100000);
camera(0, 0, (height / 2) / tan(fov / 2), 0, 0, 0, 0, 1, 0);
noFill();
stroke(190);
strokeWeight(1);
for (let i = 0; i < n; i++) {
const k = n === 1 ? 1 : i / (n - 1);
const r = S * lerp(0.02, 0.46, k);
const tilt = sin(t * params.tiltSpeed * HALF_PI - i * params.wave) * HALF_PI;
const s = 0.5 + 0.5 * sin(t * params.morphSpeed * HALF_PI - i * 0.03);
const e = lerp(1, params.roundness, s);
push();
rotateX(tilt);
beginShape();
for (let j = 0; j <= detail; j++) {
const a = (j / detail) * TWO_PI;
const c = cos(a), sn = sin(a);
vertex(
r * Math.sign(c) * pow(abs(c), 2 / e),
r * Math.sign(sn) * pow(abs(sn), 2 / e),
0
);
}
endShape();
pop();
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}