A grid of cells, a handful of rules
Falling-sand games are cellular automata dressed up as physics. The world is a grid of cells, each cell holds one material — sand, water, fire, wood, acid, smoke, empty — and every tick, each cell asks a simple, local question: what's directly below me, and what's diagonally below me? The answer decides whether the cell moves, and every material answers the question with its own tiny rulebook.
sand: if below is empty, fall straight down
else if below-left or below-right is empty, fall diagonally
else stay put
water: same as sand, but also spread sideways into empty neighbours
when it can't fall — this is what makes it pool flat
fire: has a lifespan; ignites flammable neighbours (wood); becomes smoke
smoke: rises instead of falling, dissipates over time
None of this is fluid dynamics in the physics-textbook sense — there's no pressure field, no viscosity term, no Navier–Stokes equation anywhere in the code. It's the digital equivalent of a real sandpile: individual grains obeying "fall if there's room below me" are enough, in aggregate, to produce recognisably fluid-looking behaviour, the same way Conway's Game of Life produces recognisably organic-looking behaviour from four rules with zero biology in them.
Why the update order matters
A naive left-to-right, top-to-bottom sweep through the grid creates visible bias: a cell that already fell this tick can be re-examined and fall again in the same tick, so sand appears to fall unnaturally fast down one diagonal. The standard fix is to process rows bottom-to-top (so a cell never falls into a slot that hasn't been resolved yet) and to alternate or randomise the left-right scan direction each tick, which cancels out the diagonal bias and makes sand piles settle into a symmetric angle of repose instead of leaning to one side.
Reactions: why acid, fire and water aren't independent
The interesting part of a material sandbox isn't any single substance, it's the pairwise interaction table between them: fire touching wood ignites it and eventually leaves ash; fire touching water produces steam and extinguishes; acid touching almost anything dissolves it into empty space over several ticks; water touching fire puts it out but water touching lava (if present) flashes to steam. Each rule only needs to know about its two neighbouring cell types — the rich, unpredictable-looking behaviour of a large sandbox comes from chaining many simple two-body rules across a big grid, not from any single complicated rule.
Angle of repose, in cells
Real granular materials pile up to a characteristic angle of repose — roughly 30–35° for dry sand — because a grain stays put as long as friction can resist gravity along the slope beneath it, and slides once the slope gets too steep. The sand automaton reproduces a version of this for free: a cell falls diagonally only when the two cells beside the one below it are both blocked, which geometrically limits how steep a stable sand pile can get to almost exactly a 45° cellular staircase — a coarse, grid-quantised stand-in for the smooth physical angle of repose, and a nice example of a simple local rule reproducing a real macroscopic material property.
Why this approach scales where real fluid sims don't
A physically accurate fluid simulation (solving pressure and velocity fields, as in the SPH or grid-based Navier–Stokes solvers used elsewhere on this site) needs to solve a system of equations across the whole grid every step. A falling-sand automaton only ever looks at each cell's immediate neighbours, so it's embarrassingly parallel and trivially fast — tens of thousands of active cells at 60 fps in a browser tab, with no matrix solve in sight. The trade-off is that it isn't quantitatively correct: it won't give you the right splash height or the right flow rate through a gap. What it gives you instead is something that reads as fluid, sandy, or fiery to a human eye at interactive speed, which for a sandbox toy is exactly the right trade.
Frequently asked questions
Is a falling-sand simulation real physics?
No — it's a cellular automaton, not a fluid dynamics solver. There's no pressure or velocity field; each cell just checks its immediate neighbours and moves according to per-material rules. It looks physical because the rules were designed to mimic gravity and flow, not because the underlying math is Newtonian fluid mechanics.
Why does sand sometimes look like it's flowing unevenly to one side?
That's an update-order artifact: if the grid is scanned in a fixed left-to-right, top-to-bottom order, cells that already moved this tick can get re-processed and move again, biasing everything toward one diagonal. Alternating the scan direction or randomising it each tick removes the bias.
How do materials like fire and acid interact with each other?
Through a small pairwise rule table checked at each cell boundary — fire ignites adjacent wood and is extinguished by adjacent water, acid dissolves almost any neighbour over a few ticks, and so on. Complex-looking chain reactions emerge from chaining many of these simple two-material rules across a large grid, not from any single elaborate rule.
Try it live
Everything above runs in your browser — open Sand Automaton and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Sand Automaton simulation