All projects

Experiment · 2026 · Live

Sandpile Lab

Drop sand on a grid and watch it spill onto its neighbors. One simple rule draws fractals and makes avalanches of every size, live in your browser.

RustWebAssemblyMathematicsSimulation
Sandpile Lab after growing the identity of the 256 × 256 grid: a square core framed by fractal arches
Experiment · 2026Live

Sandpile Lab

Drop sand on a grid and watch it spill onto its neighbors. One simple rule draws fractals and makes avalanches of every size, live in your browser.

What it is

A toy model of a sandpile. Grains land on a grid of squares. When a square holds four or more, it spills one grain onto each of its four neighbors, and grains that fall off the edge are gone. One spill can set off the next, until everything is calm.

That one rule is enough to draw fractals, and to make avalanches of every size, from nothing at all to a landslide across the grid. Mathematicians call it the abelian sandpile. The lab lets you watch it happen.

What you can do in the lab

  • Grow the identity. Two calm piles can be added square by square and left to spill, which gives another calm pile. One special pile changes nothing when you add it, like adding zero, and nobody can write it down by hand. The lab grows it in three steps, and its shape changes completely with the grid’s.
  • Pour a pile. Drop up to 150,000 grains on one square and they settle into a disc of nested patterns, different for every amount.
  • Set off avalanches. Drop single grains at random. The pile fills itself up to a tipping point, and from then on avalanche sizes follow a power law, with nothing tuned to get it.
  • Draw. Drop grains by hand, then add that special pile. Some piles come back exactly as they were, and the rest change into one that would.

How it runs

The engine is a Rust crate with no dependencies, compiled to WebAssembly in under 40 KB, without wasm-bindgen or any JavaScript library. The page reads pixels and histograms straight out of the module’s memory. The whole lab is one 82 KB file, and everything runs in your browser.

The checks are real mathematics. Dhar’s burning test decides which piles belong to the group. The group’s size, computed as a determinant (the matrix-tree theorem), matches a brute-force count of every stable pile on small grids: on a 3 × 3 grid both give 100,352.

Honest limits

The power law’s exponent depends on the grid size and on which avalanche sizes the fit uses. Take it as a measurement of this setup, not a universal constant. Big grids are slow to watch: the 256 × 256 identity takes about 770 million spills. The Instant button skips the animation.

How it was made

This is one of my nightly builds: an AI agent invents, builds and tests a new project every night. Sandpile Lab came out of the 18 October 2026 run.

Have a related idea? Say hello