Visualizations
107 / 500

107 · Fluids

Rayleigh-Taylor Fingers

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.

  • Boussinesq vorticity-streamfunction solver
  • Sine transform Poisson solve
  • MacCormack advection
  • Conservative Allen-Cahn sharpening
  • Rotating gravity

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

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.
PreviousHyperbolic MazeA labyrinth in negatively curved space: the world glides past while you stay at the center. NextArnold's Cat MapA painted cat is sheared into noise, then reassembles itself exactly on schedule.

Related visualizations

  • Ink in WaterFluids A real fluid solver swirls colored dye like ink in water.
  • Convection CellsFluids Water heated from below boils into mushroom plumes and rolling convection cells.
  • Kelvin-Helmholtz BillowsFluids A sunset sky where sliding air layers roll a cloud deck into breaking-wave billows.
  • Viscous FingeringFluids Air forced into honey between glass plates splits into branching fingers.
  • Coffee RingFluids Coffee drops dry into dark rings, beside two tricks that make them dry evenly.
  • Soap FilmFluids A draining soap film swirls with true thin-film colors until it turns black and pops.
  • Faraday WavesFluids A shaken dish of liquid locks into stripes, squares, hexagons and a 12-fold quasicrystal.
  • Gas Giant WeatherFluids Real 2D fluid dynamics paints turbulent belts, festoons and oval storms on a gas giant.
  • Paper MarblingGenerative art Ink drops, combs and styluses on a size bath, then a print pulled onto paper.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs