Heavy ink collapses into mushroom fingers in a glass tank you can turn upside down.
A heavy cobalt ink rests on a light amber one. Any ripple lets heavy fluid slip down beside rising light fluid, buoyancy spins the interface into vortex pairs, and the fingers grow mushroom caps that curl into ever finer swirls, the same instability that shapes supernova remnants. The flow is 2D Boussinesq in vorticity and stream function form with free-slip glass walls, inverted exactly every step with a sine transform across the tank and a tridiagonal solve down it. Density and a marbling tint dye ride a grid three times finer with MacCormack advection, and a weak, volume-conserving Allen-Cahn term keeps the two inks distinct so the tank can be flipped again and again. While the tank turns, gravity rotates in the fluid's frame, so it sloshes as it goes over.
Try it. Press Flip tank (or G, F or Space) to turn the tank over and start again. Drag the Atwood slider or use the arrow keys to set the density ratio. Tap the fluid to poke it along gravity and seed a new finger, or drag through it to stir. R refills the tank. Left alone, it flips itself once the heavy ink has settled and refills after every third flip.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a Rayleigh-Taylor instability simulation with JavaScript and the HTML canvas element: a heavy fluid resting on a light one in a tank, collapsing into mushroom-capped fingers. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Use a grid of about 128 x 80 cells with solid walls on all four sides. Store vorticity w and a density field rho (1 for the heavy fluid on top, 0 for the light one below), with a slightly wavy interface across the middle.
- Each step: get velocity from a stream function psi (u = dpsi/dy, v = -dpsi/dx), advect w and rho with semi-Lagrangian advection (trace each cell back along the velocity and bilinearly sample), add buoyancy to the vorticity (w += dt * g * drho/dx with y pointing down), apply a little viscosity, then solve lap(psi) = -w with psi = 0 on the walls using Jacobi or Gauss-Seidel iterations warm-started from the last frame.
- Draw rho as two ink colors into ImageData on a small offscreen canvas and scale it up with drawImage.
Once that works, make it beautiful:
- Pick two inks that look good together, such as deep cobalt over warm amber, and add faint horizontal tint bands in each layer so you can see how the fluid folds.
- Keep rho on a grid two or three times finer than the flow and use MacCormack advection, so the fingers stay sharp. Darken the interface slightly so curls read clearly.
- Draw the fluid inside a glass tank with a frame and a soft reflection.
- Add a key that flips gravity, ideally by animating the tank turning over while gravity rotates in its frame, plus a slider for the density ratio (the Atwood number).
- Let a click poke the interface to seed a new finger.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as an exact sine-transform Poisson solver, an Allen-Cahn term to keep the inks from mixing, or surface tension.