p5.js
Tide Rings
A dark pool. Every touch drops a ring into it, and the rings cross, fade and light each other. No touching? The pool breathes on its own.
Licence: CC BY-NC-SA 4.0: remix with credit, non-commercial, share alike
View the code
// Tide Rings — a p5.js pool of ripples
// Touch the water: every tap and drag drops a ring, and the rings cross and
// light each other up. Idle, the pool drops its own slow rings.
// Palette: charcoal, bone, signal orange.
// Site sliders: Rings · Size · Fade · Dots — read through params.*
const BONE = [233, 229, 218];
const ORANGE = [255, 180, 84];
const BG = [13, 13, 18];
let rings = [];
let lastAuto = 0;
let lastTouch = -99;
function setup() {
createCanvas(windowWidth, windowHeight);
background(...BG);
}
function drop(x, y, orange) {
rings.push({ x, y, r: 2, max: min(width, height) * (params.size ?? 0.5) * random(0.75, 1.1), orange });
if (rings.length > 42) rings.shift();
}
function draw() {
noStroke();
fill(BG[0], BG[1], BG[2], params.fade ?? 26);
rect(0, 0, width, height);
if (mouseIsPressed && mouseX > 0) {
if (frameCount - lastTouch > 9) { drop(mouseX, mouseY, random() < 0.5); lastTouch = frameCount; }
}
const rate = params.rings ?? 1;
if (rate > 0 && frameCount - lastAuto > 56 / rate) {
const a = random(TWO_PI), rr = random(0.1, 0.36) * min(width, height);
drop(width / 2 + cos(a) * rr, height / 2 + sin(a) * rr, random() < 0.45);
lastAuto = frameCount;
}
const dots = round(params.dots ?? 10);
for (let i = rings.length - 1; i >= 0; i--) {
const g = rings[i];
g.r += 2.6;
const life = 1 - g.r / g.max;
if (life <= 0) { rings.splice(i, 1); continue; }
const col = g.orange ? ORANGE : BONE;
noFill();
stroke(col[0], col[1], col[2], 170 * life);
strokeWeight(1.6);
ellipse(g.x, g.y, g.r * 2);
stroke(col[0], col[1], col[2], 85 * life);
strokeWeight(1.1);
ellipse(g.x, g.y, g.r * 1.72);
if (dots > 0) {
noStroke();
fill(col[0], col[1], col[2], 200 * life);
for (let k = 0; k < dots; k++) {
const a = (k / dots) * TWO_PI + g.r * 0.01;
ellipse(g.x + cos(a) * g.r, g.y + sin(a) * g.r, 3.2);
}
}
}
}
function mousePressed(e) {
if (e && e.target && e.target.tagName !== 'CANVAS') return;
drop(mouseX, mouseY, random() < 0.5);
}
function keyPressed() {
if (key === 's' || key === 'S') saveCanvas('tide-rings', 'png');
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
background(...BG);
}