A falling-sand sandbox is a 2D cellular automaton where every pixel is a cell of sand, water, lava, stone, plant, gas or fire, and each cell follows a handful of simple local rules. Out of those rules emerge surprisingly lifelike behaviours: sand piles up, water finds its level, lava sets plants ablaze and meets water to form stone. The same idea powers granular-flow research, geology models and acclaimed games such as Powder Game and Noita.
next(x, y) = rule(state(x, y), neighbours(x, y)) — each cell's new state depends only on itself and its immediate neighbours. Gravity is modelled as a preference to move to (x, y+1) when empty, with diagonal fallback to (x±1, y+1); column update order is shuffled each step to remove directional bias.
The "falling sand" genre exploded after the 2005 Japanese web toy Powder Game, but the underlying idea — that complex patterns emerge from trivial local rules — is the same one John Conway used in his 1970 Game of Life, one of the most studied cellular automata in all of mathematics.
Draw with sand, water, fire, wood, acid and smoke — watch substances interact with physics and chemistry rules. Fire ignites wood, acid dissolves materials, water pools at the bottom.
Each pixel is a cell that follows rules: sand falls with gravity and piles at the angle of repose, water flows and fills cavities, fire uses cellular combustion rules.
Select a substance and draw with the mouse. Combine materials to see reactions: fire + wood = smoke, acid dissolves most materials, water extinguishes fire.
This "falling sand" genre traces back to 1986's Tetris-inspired experiments and the 2005 classic "Powder Game". Modern games like Noita (2020) push pixel physics to extraordinary complexity.
This sandbox is a two-dimensional cellular automaton in which the screen is divided into a grid of small cells, each holding one material: sand, water, lava, stone, plant, gas, or the steam and fire that reactions produce. Every cell obeys a few simple local rules, expressed as next(x,y) = rule(state, neighbours). From these trivial rules complex, lifelike granular and fluid behaviour emerges across the whole grid.
The grid is scanned from the bottom row upward, with the column order shuffled each step to remove directional bias. Sand falls and slides diagonally to its angle of repose, water flows down then spreads sideways, gas and steam rise, and neighbours react: lava meeting water becomes stone and steam, while lava or fire ignites plant. Such models underpin granular-flow research, geology, and games like Powder Game and Noita.
What is a falling-sand simulation?
It is a cellular automaton where the canvas is a grid of cells, each storing one material type. Each cell follows simple local rules every frame, and the collective result looks like sand, water and fire behaving physically. It is a sandbox toy, not a precise fluid solver.
How does the simulation actually work?
On every physics step the grid is scanned from the bottom row up. Each non-empty, non-stone cell tries to move according to its material rule, and reactions between neighbouring cells are checked. The new state of any cell depends only on itself and its immediate neighbours.
What do the controls do?
The material buttons select what you paint: Sand, Water, Lava, Stone, Plant, Gas or Erase. Brush size sets the radius of the circular area painted, from 1 to 20 cells. Speed sets how many physics steps run per rendered frame, from 1 to 8. Clear empties the entire grid.
Scanning columns left to right would bias movement toward one side, so sand and water would drift in a preferred direction. Shuffling the column order every step averages this out, giving symmetric, more natural-looking piles and flows.
A sand cell first tries to fall straight down into an empty cell or to displace water below it. If blocked, it attempts to slide diagonally into an empty cell below-left or below-right. This diagonal sliding is what builds the characteristic sloped pile rather than a vertical stack.
Lava falling onto water turns the water to stone and leaves steam behind. Lava and fire can ignite neighbouring plant cells, which then burn as fire. Fire spreads to adjacent plant, burns out into gas, and gas slowly dissipates. Plant can also spread slowly where it touches water.
Only loosely. Water falls when there is empty space below, otherwise it tries to spread sideways up to three cells. This produces convincing pooling and levelling, but it ignores pressure, viscosity and incompressibility, so it is a qualitative approximation rather than a Navier-Stokes fluid solver.
It captures the qualitative essence of granular and fluid motion: gravity, piling, flowing and simple phase reactions. It is not quantitatively accurate, because cells move at most one step per frame on a coarse grid using probabilistic rules, with no real forces, momentum or units.
Speed sets how many physics steps are computed for each frame the browser draws. At a value of 1 the simulation advances one step per frame; at 8 it advances eight, so materials settle and react much faster, at the cost of more computation per frame.
Empty cells have nothing to move, and stone is treated as a static solid that does not fall or react. Skipping both keeps the per-frame loop fast, so the simulation can run thousands of active cells smoothly while still checking every potentially moving particle.
Both are cellular automata whose global behaviour emerges from simple rules applied to each cell based on its neighbours. The Game of Life, devised in 1970, popularised the idea that trivial local rules can create rich patterns; falling-sand toys apply the same principle to granular and fluid materials.