Fluid demo: a little boat in a box of water

This page runs a real 2D incompressible fluid solver in your browser via WebAssembly, compiled from the fluid-sim Rust code — Jos Stam's "Stable Fluids": semi-Lagrangian advection plus a pressure solve that enforces incompressibility every frame. Drag anywhere to stir dye into the water, or grab the boat and drag it — or drive it like a real boat: W/S throttle, A/D rudder (arrow keys work too) — and watch the wake.

View:
0
5
0.002
30
starting…

How it works (60 seconds)

  1. Advect. Every cell traces backwards along the velocity field and interpolates — unconditionally stable, which is why you can drag as violently as you like without it exploding. The price is smearing: fine vortices fade unless vorticity confinement (the slider) re-injects swirl.
  2. Project. Advection leaves the velocity field compressed (nonzero divergence). The solver computes ∇²p = ∇·u with Jacobi iteration and subtracts ∇p, leaving the flow incompressible. This is the expensive step — drop pressure iters to 4 and watch the sim turn to mush.
  3. Solids. The boat is a rasterized mask whose cells are pinned to the boat's velocity each frame (no-slip in the body's frame). The wake, the bow wave, the shedding eddies — all emergent.

The two equations being solved, every frame, on a 128×128 grid:

∂u/∂t = −(u·∇)u − ∇p/ρ + ν∇²u + f
∇·u = 0

Things to try

Further reading

The full writeup lives in the fluid-sim README. Each piece has a deeper explainer, each readable in one sitting:

← back to demos