Build a 2D ripple tank as a single HTML file at 1280x720 with a dark deep-slate and teal look, vanilla JS and canvas only, no libraries. Simulate shallow water with the wave equation on a 640x360 grid using two Float32Array buffers (cur and prev): next = (2*cur - prev + c2*laplacian(cur)) * damping, with c2 0.4, then swap the buffers. Add a per-cell damping array with an absorbing rim 48 cells wide so waves leave quietly, and a loss-per-step value of 0.0006 that a Damping slider (0 to 0.01) controls. Clicking the water drops a pebble: a smooth dent with a few rings (gaussian envelope times a cosine, offset so it sums to zero) that throws a short wave train. Render by shading every cell from its height gradient: build a normal, add a tight white specular highlight from a key light at the left plus a softer teal rim light from the right, add caustics from the negative laplacian (concave water focuses light), and read a procedural tank floor (faint tile grid, a center glow, soft mottling) through a refraction offset so the grid bends under the crests. Colors are indigo and teal on near-black, highlights white and aqua. Draw the 640x360 shading into an offscreen canvas and scale it up smoothly to 1280x720. Put the wave solver, pebble and shading in wave.js, the floor generator in floor.js, and add a glass title card top left, a glass panel bottom left with the Damping slider and a Clear button, and a hint bottom right that says click the water to drop a pebble. Run 4 wave steps per frame, and expose window.tick(n) and window.drop(x, y, r, a) with a ?manual=1 mode so screenshots are deterministic.
two buffers and a laplacian is the whole wave equation. shade from the height gradient, since the slope is what catches the light and the height alone just looks flat.
// wave.js, step 1: two-buffer wave equation, pebbles and normal-based shading
class Wave {
constructor(W, H, c2 = 0.4) {
Object.assign(this, { W, H, c2, cur: new Float32Array(W * H), prev: new Float32Array(W * H), sponge: new Float32Array(W * H) });
this.setDamping(0.0006);
}
setDamping(loss) { // loss per step, plus an absorbing rim so waves leave quietly
const { W, H, sponge } = this, rim = 48; this.loss = loss;
for (let y = 0; y < H; y++) for (let x = 0; x < W; x++) {
const e = Math.max(0, rim - Math.min(x, y, W - 1 - x, H - 1 - y)) / rim;
sponge[y * W + x] = (1 - loss) * (1 - 0.09 * e * e);
}
}
step() {
const { W, H, c2, cur, prev, sponge } = this;
for (let y = 1; y < H - 1; y++) for (let i = y * W + 1, e = i + W - 2; i < e; i++) {
const lap = cur[i - 1] + cur[i + 1] + cur[i - W] + cur[i + W] - 4 * cur[i];
prev[i] = (2 * cur[i] - prev[i] + c2 * lap) * sponge[i]; // next height lands in the old buffer
}
this.cur = prev; this.prev = cur; // swap the two buffers
}
drop(cx, cy, r = 5, amp = -1.9) { // a pebble is a dent with a few rings, so it throws a short wave train
for (let y = -4 * r; y <= 4 * r; y++) for (let x = -4 * r; x <= 4 * r; x++) {
const px = cx + x, py = cy + y, d = Math.hypot(x, y);
if (px > 0 && py > 0 && px < this.W - 1 && py < this.H - 1)
this.cur[py * this.W + px] += amp * Math.exp(-d * d / (2.5 * r * r)) * (Math.cos(d / (0.45 * r)) + 0.257); // +0.257 makes the stamp zero-mean, so no slow blob follows it
}
}
shade(img, floor) { // normals from height gradients: specular crests plus caustics
const { W, H, cur: u } = this, d = img.data, key = [-0.62, -0.18, 1.68], fill = [0.6, 0.12, 1.7]; // two half-vectors
const kn = Math.hypot(...key), fn = Math.hypot(...fill);
for (let y = 1; y < H - 1; y++) for (let x = 1; x < W - 1; x++) {
const i = y * W + x, dx = (u[i + 1] - u[i - 1]) * 4, dy = (u[i + W] - u[i - W]) * 4;
const lap = u[i - 1] + u[i + 1] + u[i - W] + u[i + W] - 4 * u[i];
const fx = Math.min(W - 1, Math.max(0, Math.round(x + dx * 6))), fy = Math.min(H - 1, Math.max(0, Math.round(y + dy * 6)));
const f = floor[fy * W + fx], inv = 1 / Math.hypot(dx, dy, 1); // floor read through the refraction
let s = Math.max(0, (-dx * key[0] - dy * key[1] + key[2]) * inv / kn);
let g = Math.max(0, (-dx * fill[0] - dy * fill[1] + fill[2]) * inv / fn);
s *= s; s *= s; s *= s; s *= s; s *= s; // tight white highlight, s^32
g *= g; g *= g; g *= g; g *= g; g *= g; g *= g; // softer teal rim light, g^64
const c = Math.max(0, -lap * 1.1), o = i * 4; // concave water focuses light
d[o] = 7 + 14 * f + 14 * c + 215 * s + 40 * g;
d[o + 1] = 14 + 54 * f + 175 * c + 240 * s + 190 * g;
d[o + 2] = 36 + 66 * f + 170 * c + 250 * s + 200 * g;
d[o + 3] = 255;
}
}
}








