Falling Sand Game

Play the falling sand game in your browser. Pour sand, water, oil, plants, acid and lava, set fires that spread and burn out, and drop lava into water to make stone and steam. Free, no download, works on touch.

Sandbox

Sand · 7-cell brush

Drag or draw with one finger. Pick two materials and make them meet.

FPS · 0.00 ms · 4% full

Materials

Select a material, then paint it into the sandbox.

Selected: Sand

Brush & speed

7 cells
FineWide
1×
0.25×

Starting scenes

Loading a scene replaces everything currently in the sandbox.

Try these reactions

  • • Pour sand into water and watch density pull it through.
  • • Put oil on water, then touch the oil with fire.
  • • Drip water onto lava to make stone and steam.
  • • Build a stone cup before filling it with acid.
Advertisement

Things worth trying

Build a container first. Draw a bowl out of stone, then pour water into it. Stone is the only material that never moves and the only one acid cannot eat, so it is what everything else gets tested against.

Layer oil on water. Pour water into a container, then oil on top. The oil settles above the water because it is less dense. Now drop a single spark of fire on it.

Drop lava into water. Each contact turns the lava to stone and the water to steam. Pour lava slowly into a full container and you can build a stone plug that stops the rest getting through.

Feed a plant. Plants creep along wet cells, so a plant next to water spreads. Let it dry out and set it alight to watch fire follow the growth.

Pour acid on a sand pile inside a stone box. The sand disappears and the box survives, which is the difference the rules draw between the two.

How a falling sand game actually works

There is no physics engine here. The world is a grid of integers and one short rule per material, applied to every cell each frame:

  1. If the cell below is empty, move into it.
  2. Otherwise, if the cell below holds something less dense, swap with it.
  3. Otherwise, try the two diagonals below.
  4. Liquids also try left and right, which is what makes them find their level.

Everything people recognise as sand behaviour - pouring, piling at an angle, settling - comes out of those four lines rather than being modelled.

Two details do most of the work. The grid is scanned bottom-up, because scanning downward would let a single grain fall the whole height in one frame as the loop kept catching up with it. And the scan direction alternates each row, since always sweeping the same way biases which diagonal wins and makes piles lean visibly to one side.

Why it stays fast

Drawing thirty thousand cells as individual rectangles would be far too slow to hit sixty frames a second. Instead the grid is written straight into an ImageData buffer at one pixel per cell, and that small image is scaled up to the canvas with smoothing switched off, which gives the crisp pixel look as a side effect.

Colours come from a table computed once at startup, so no colour strings are built inside the frame loop.

Measured on the full 200 by 150 grid with around seventeen thousand cells occupied, a simulation step takes about a third of a millisecond - roughly a twentieth of the budget available at sixty frames a second, leaving the rest for rendering and interaction.

Frequently Asked Questions

What materials can I use?+

Sand, water, stone, oil, fire, smoke, steam, plant, acid and lava. Stone is the inert one - use it to build containers that hold everything else.

How do the materials interact?+

Water puts out fire and turns to steam near lava. Lava sets fire to anything flammable and hardens into stone when water touches it. Oil floats on water and catches fire readily. Acid eats through most things but not stone. Plants grow along wet cells and burn well once dry.

Why does sand sink through water while oil floats on it?+

Because each material has a density and a cell swaps with the one below it when that one is lighter. Sand is denser than water so it sinks; oil is lighter so it rises. Neither behaviour is special-cased - both fall out of the same rule.

Is this a physics engine?+

No, and that is what makes it fast. There are no particles with velocities, just a grid of cells and a short list of rules applied to each one every frame. Pouring, piling and flowing are emergent from those rules rather than simulated directly.

Does it work on a phone or tablet?+

Yes. Drag with a finger to paint, and the canvas will not scroll the page while you are drawing on it.

Can I save what I make?+

You can download the current state as a PNG.

Is anything uploaded?+

No. The whole simulation runs in your browser and nothing is sent anywhere.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.