Fluid Simulation

Stir a real-time fluid with your mouse and watch dye and velocity swirl across the grid. Every frame solves a stable form of the Navier–Stokes equations — the same maths behind real liquids and gases — right here on your device. Drag to inject colour, drop in random splats, and tune the viscosity and fade. Nothing is uploaded.

You are in the Physics lab.

Click and drag to stir the fluid
Frames/sec0
Grid128×128
Real fluid maths, running on your device. Every frame this solves a stable form of the Navier–Stokes equations using Jos Stam's 1999 "Stable Fluids" method — entirely in your browser, with nothing sent to a server. The same equations, in 3D and at far higher resolution, drive the smoke, water and fire you see in visual-effects shots in films.

How It Works

Three steps run every frame to move the fluid and its dye.

1

Advection

The fluid carries things along with it. Each cell looks backwards along the velocity field to find where its contents came from a moment ago, then pulls that velocity and dye forward. This is what makes dye streak and swirl instead of sitting still.

2

Diffusion & viscosity

Neighbouring cells exchange velocity so the flow smooths out over time — that is viscosity, the fluid's internal friction. Raising the viscosity slider makes the motion thick and syrupy; lowering it makes it thin and free-flowing.

3

Projection

A real fluid conserves mass — it cannot pile up or vanish. The projection step corrects the velocity field so it is incompressible, which is exactly what creates the rolling vortices. Without it, the flow would look flat and lifeless.

What is this fluid simulation actually computing?
Every frame it advances a velocity field and coloured dye across a 128×128 grid by solving a stable form of the Navier–Stokes equations — the equations that govern how liquids and gases move. When you drag, you inject velocity and dye, and the solver carries them along the flow to produce the swirling vortices you see.
What are the Navier–Stokes equations?
They describe the motion of fluids by conserving momentum and mass — how a fluid is pushed by forces, resists motion through viscosity, and stays incompressible. This lab uses Jos Stam's 1999 "Stable Fluids" method, which stays stable at any time step so it can run smoothly in real time.
Is this real physics, and what are its limits?
It uses the same governing equations as real fluid dynamics, so the qualitative behaviour — swirling, mixing, diffusion — is physically motivated. But it trades accuracy for speed: a coarse grid, a modest number of solver iterations, and the numerical smoothing built into Stam's method all dampen the finest turbulent detail. It is a visual, educational model, not an engineering-grade solver.
Can I put this on my own website?
Yes. There is an embeddable version at lkforge.com/embed/fluid-sim/ that you can drop into an <iframe>. It runs entirely client-side with no tracking.