Visualizations
101 / 500

101 · Emergence

Sandpile Identity

The identity of the sandpile group: a fractal carpet woven from pure algebra.

In the Abelian sandpile any cell holding four or more grains topples, sending one grain to each neighbor and losing grains off the edge, and the order of topplings never changes the final state. The stable recurrent piles form a finite group whose identity element e is not the empty pile but this intricate carpet, computed exactly as e = (2m - (2m)°)°, where m is 3 grains everywhere and ° means topple until stable. On a 254 by 254 grid that takes about 750 million topplings, spread over frames and sped up by toppling each cell floor(h/4) times per visit and by simulating one quarter of the square with mirror edges. The storyboard shows the four stages, the demo then checks e + e = e cell for cell, and palettes borrow from Japanese textiles under a plain-weave texture.

Try it. Click the carpet to drop a pile of grains and watch the avalanche weave a mandala; drag to pour grains continuously. Keys 1 to 5 set the pile size, E adds e to itself, P changes the textile palette, Space restores the identity, and R recomputes it from scratch. Left alone it proves e + e = e, then drops piles.

  • Abelian sandpile group
  • Multi-toppling Gauss-Seidel sweeps
  • Quarter-symmetry with mirror boundaries
  • Pattern fills with multiply blending

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Compute and draw the identity element of the Abelian sandpile group with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window and stays sharp on high-DPI screens. Use a square grid of about 128 x 128 cells in an Int32Array, with one extra border cell on each side that acts as a sink (grains that land there are thrown away).
- Write stabilize(): sweep the grid repeatedly; any cell with 4 or more grains topples floor(h / 4) times at once, keeping h mod 4 and giving that many grains to each of its four neighbors. Stop when a sweep changes nothing.
- Compute the identity with the formula e = (6 - (6)stab)stab: fill every cell with 6, stabilize, replace each cell h with 6 - h, and stabilize again.
- Draw it at one pixel per cell into an ImageData with four colors for 0, 1, 2 and 3 grains, scaled up with image smoothing off.

Once that works, make it beautiful:
- Spread the sweeps over animation frames with a time budget of about 8 ms, and draw the grid as it topples so you can watch the carpet emerge.
- Use palettes inspired by Japanese textiles, such as indigo, cream and pale blue, or vermilion, gold and black, and lay a faint woven texture over the cells with a pattern fill and multiply blending.
- Verify that adding e to itself and stabilizing gives e back, and show the result.
- Let a click drop a few thousand grains on the identity and animate the avalanche.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as computing the identity on other shapes like a disk or a triangle, using the square's symmetry to simulate a quarter of the grid, or exploring the inverse of a configuration in the group.
PreviousPlucked StringsSeven finite-difference strings to pluck, with live harmonics and slow-motion kinks. NextDifferential GrowthOne closed line grows, buckles and folds into brain coral without ever crossing.

Related visualizations

  • Wallpaper GroupsGenerative art Paint once and any of the 17 plane symmetry groups repeats the stroke across the plane.
  • CooperationEmergence A few defectors in a sea of cooperators unfold into an endless symmetric kaleidoscope.
  • Ant FarmEmergence A colony digs its nest grain by grain behind glass, with no plan but local rules.
  • Cell SortingEmergence A Cellular Potts tissue unmixes itself by differential adhesion, on a stained slide.
  • Particle LifeEmergence Colored particles with simple attractions that assemble into living cells.
  • Wythoff Kaleidoscope3D One draggable seed in a mirror triangle generates every convex uniform polyhedron.
  • Indra's PearlsFractals Limit sets of Kleinian groups, strung as glowing necklaces of nested circles and pearls.
  • Marching CubesAlgorithms Watch the classic isosurface algorithm march cell by cell, then zoom out to clay.
  • IFS EditorFractals Sculpt fractals by dragging affine parallelograms while the chaos game redraws them.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs