Abelian Sandpile

Drop grains of sand on a grid and watch them topple into a fractal, directly in your browser.

This free online abelian sandpile simulator runs one of the most famous cellular automata: grains of sand are dropped on a grid, and every cell that holds 4 grains or more topples, giving one grain to each of its 4 neighbors. Those neighbors may topple in turn, in avalanches that go on until every cell holds 0, 1, 2 or 3 grains.

Pour hundreds of thousands of grains on a single cell, and the stable pile that remains is a surprising fractal, with nested triangles, patches and symmetric patterns. Try one pile or several piles, fill a rectangle with sand, or compute the identity of the sandpile group, one of the most beautiful images of mathematics.

Follow the avalanches step by step, at the speed you choose, drop the grains one at a time, or click on the image to drop a grain where you want. Choose the colors of each number of grains and download the result as a PNG image, or download an animation as a video or GIF, showing the pile growing grain by grain or the sand toppling. Everything runs directly in your browser: nothing is uploaded to a server.

Examples
The sand
The simulation
In a step, every cell with enough grains topples once, all at the same time, so the grains given in a step only arrive at the next one. Best to follow the avalanches.
The image
Image size: 2 x 2 px
The colors
The animation
The grains are added little by little, and every frame shows a stable pile. The grains added by clicking on the image are not included.
The pile changes the most at the beginning. Accelerating gives more time to the beginning, so the pile grows at a steady pace.
The animation can be created once the sand is stable.
Download
Grains: 131072Grid: 1 x 1 cellsSteps: 0

How to generate an abelian sandpile

  1. Choose where to drop the sand - Pour it on piles in the center of the grid, put the same number of grains on every cell of a rectangle, or compute the identity of the sandpile group of a rectangle.
  2. Choose the amount of sand - For the piles, choose the number of grains, or click one of the buttons from 16K to 1M grains. More grains give a bigger and more detailed fractal, but take longer to compute.
  3. Choose the neighbors - With 4 neighbors, a cell topples when it has 4 grains. With 8 neighbors, including the diagonals, it topples when it has 8 grains, which gives a denser pile with a completely different pattern.
  4. Choose the algorithm - The synchronous algorithm makes the textbook steps, where every unstable cell topples once at the same time, so you can follow the avalanches. The row-by-row algorithm gets to the same final image much faster.
  5. Choose how to drop the grains - For the piles, drop all the grains at once, or one at a time: each grain falls when the avalanche of the previous one has ended.
  6. Watch it topple - The image is drawn while the sand is still toppling, as fast as possible or at the number of steps per second you choose. The computation stops by itself when every cell is stable.
  7. Pause and go step by step - Click "Pause" to freeze the toppling, then "Next step" to make one step per click (or 10, 100 or 1000 steps, chosen beside the button), or "Resume" to let it run again. Once the sand is stable, "Replay step by step" starts again from the first step, already paused.
  8. Drop grains by clicking - While the toppling is paused, or once the sand is stable, click on a cell of the image to drop a grain on it, and follow the avalanche it causes with "Next step" or "Resume".
  9. Customize the colors - Choose a palette, or pick your own color for each number of grains, and for the unstable cells that are still toppling. The cells with 0 grains can be transparent.
  10. Download the image - Choose the size of each cell in pixels and click "Download image" to save the result as a PNG image.
  11. Download the animation - Once the sand is stable, choose between a growing pile and the steps of the preview, the format (WebM video or animated GIF), the duration and the speed, then click "Download video" or "Download GIF".

What is the abelian sandpile?

The abelian sandpile model, also known as the Bak-Tang-Wiesenfeld model, was introduced in 1987 by the physicists Per Bak, Chao Tang and Kurt Wiesenfeld as the first example of self-organized criticality: a system that evolves by itself to a critical state, where a single added grain may cause an avalanche of any size.

The rule is simple. Every cell of a grid holds a number of grains of sand. When a cell holds 4 or more grains, it topples: it loses 4 grains and gives one to each of its 4 neighbors. The grains that fall off the border of a finite grid are lost. The toppling goes on until every cell holds fewer than 4 grains, and the configuration is stable.

It is called abelian because the order of the topplings does not matter: whatever order you choose, the final stable configuration is always exactly the same. That property, proven by Deepak Dhar, is what makes it possible to compute a million grains quickly: the row-by-row algorithm of this tool topples each cell with all its grains at once, and both algorithms only compute one quarter of a symmetric pile.

The identity of the sandpile group

On a finite grid, the stable configurations that can be reached from any other configuration by adding grains are called recurrent. They form a group, where the sum of two configurations is their cell by cell sum, stabilized. Like every group, it has an identity element: a configuration that changes nothing when it is added to another one.

The identity is computed as stabilize(2m - stabilize(2m)), where m is the configuration with 3 grains on every cell. It depends on the size of the rectangle, and it is a striking fractal pattern, usually with a big square in the center, nested triangles and curved borders.

ModeDescription
One pile in the centerAll the grains are dropped on the center cell of an infinite grid. The pile grows into an almost round shape filled with a fractal pattern.
Four and five pilesSeveral piles of the same size, at a distance you choose. They grow until they meet, and their patterns interfere where they touch.
The same number of grains on every cellEvery cell of a rectangle starts with the same number of grains, and the grains fall off its borders. The result is full of straight lines and self-similar patterns.
Identity of the sandpile groupThe identity element of the sandpile group of the rectangle, computed with two stabilizations.

Options

Below are all the options you can configure in this abelian sandpile simulator.

FieldDescription
Where to drop the sandPiles of sand in the center of an infinite grid, the same number of grains on every cell of a rectangle, or the identity of the sandpile group of a rectangle.
PilesOne pile in the center, four piles on the corners of a square, or five piles in a cross (the center and four piles around it).
Number of grainsThe number of grains of each pile, up to 2000000. The size of the final pile grows with the square root of the number of grains.
Distance between the pilesThe distance, in cells, from the center to the other piles.
Width and height of the rectangleThe size of the rectangle of the uniform and identity modes, up to 800 cells. The grains that leave the rectangle are lost.
Grains on every cellThe number of grains put on every cell of the rectangle in the uniform mode.
NeighborsWith 4 neighbors (von Neumann neighborhood), a cell topples with 4 grains and gives one to each side. With 8 neighbors (Moore neighborhood), it topples with 8 grains and also gives one to each diagonal.
AlgorithmSynchronous: the textbook step, where every cell with enough grains topples once, all at the same time, based on the grid as it was before the step. The grains given in a step only arrive at the next one, so the avalanches can be followed step by step. Row by row: in a step, the grid is read row by row and updated at once, and every cell with enough grains gives all the grains it can. A cell can topple in the same step in which it received grains, so it needs far fewer steps and is much faster. Both end on exactly the same image.
Drop the grainsAll at once: all the grains are on the piles at the first step. One at a time: one grain falls on each pile, its avalanche runs until every cell is stable, and then the next grain falls, as in the original sandpile model.
SpeedHow many steps are shown per second, from 1 to 60, or as fast as possible to get the final image quickly. It can be changed while the sand topples.
Steps per clickWhile the toppling is paused, the number of steps made by each click on "Next step": 1, 10, 100 or 1000.
Size of the cellThe size of each cell in pixels, which sets the size of the downloaded image.
Margin around the pilesThe number of empty cells left around the piles in the image.
PaletteThe colors of the cells with 0, 1, 2 and 3 grains, plus a color for the unstable cells, which hold enough grains to topple (4 or more, or 8 or more with 8 neighbors). The unstable cells only appear while the sand is toppling, in the preview and in the toppling animation, so the final image never has them. With 8 neighbors, the 4 colors of the stable cells are stretched into a gradient of 8 colors.
Transparent cells with 0 grainsLeaves the cells with 0 grains transparent in the downloaded PNG image, including all the space around the piles. The animations always use the color of the cells with 0 grains.
AnimationGrowing pile: the grains are added little by little, and every frame shows a stable pile with more grains than the previous one; the grains added by clicking are not included. Step by step, like the preview: the frames show the steps of the preview, with the same algorithm, the same way of dropping the grains and the grains added by clicking, at the same steps. The other modes always show the steps. Both end on the same image, because the order of the topplings doesn't change the result.
FormatA WebM video, or an animated GIF that plays everywhere but makes bigger files and allows fewer frames per second.
DurationHow long the sand moves, from 1 to 120 seconds. A shorter animation goes faster.
Frames per secondMore frames make a smoother animation and a bigger file. GIF only supports 10, 20, 25 and 50 frames per second.
SpeedConstant spreads the grains (or the steps) evenly over the frames, so the pile grows very fast at the beginning and slowly at the end. Accelerating starts slowly, so that the size of the pile grows at a steady pace.
Keep the final image at the endHow many seconds the stable pile stays on screen at the end of the animation.

Frequently Asked Questions (FAQ)

Is this abelian sandpile simulator free?

Yes. The tool is completely free, there is no registration, and everything is computed by your own browser: nothing is uploaded to a server.

Why is it called a sandpile?

Because it models a pile of sand where grains are added one at a time: most grains just stay where they fall, but sometimes one grain too many causes an avalanche that runs down the whole pile. The model was created to study that kind of avalanche, which also appears in earthquakes, forest fires and stock markets.

Why does the pile look like a fractal?

Nobody fully knows why. The patterns of the stable pile were studied by mathematicians like Lionel Levine, Wesley Pegden and Charles Smart, who proved that the pile has a limit shape as the number of grains grows, and that its patterns are related to Apollonian circle packings.

How long does it take to compute?

The number of topplings grows very fast with the number of grains. On a typical computer, with the row-by-row algorithm, 131072 grains take less than a second, 524288 grains take a few seconds and a million grains take around 40 seconds. The synchronous algorithm, made to follow the avalanches step by step, is about 4 times slower: about 2 seconds for 131072 grains and 2 to 3 minutes for a million grains, with 4 neighbors. The image is drawn while the sand topples, so you can follow the progress.

Does the order of the topplings change the result?

No. That is the "abelian" property of the model: the final stable pile is always the same, whatever the order of the topplings. It is also why the pile is perfectly symmetric.

Can I watch the sand topple step by step?

Yes. Choose a speed of a few steps per second, or click "Pause" below the image while the sand is toppling, then click "Next step" to make one step at a time. With the synchronous algorithm, every cell with enough grains topples once in each step, and the cells that are still unstable are drawn with a color of their own, so you can see which cells will topple next. A big pile needs many thousands of steps, so you can also choose 10, 100 or 1000 steps per click. Small piles become stable in a fraction of a second, so for those, wait until the end and click "Replay step by step" to start again from the first step. The image can be downloaded while the computation is paused.

What is the difference between the two algorithms?

The synchronous algorithm makes the textbook steps: all the unstable cells topple at the same time, each losing exactly 4 grains (or 8), and the grains they give only count from the next step. A cell holding thousands of grains topples once in every step, so it takes many steps, but you can watch the sand spread exactly as the model describes it. The row-by-row algorithm reads the grid in order and updates it at once: a cell gives all the grains it can in one go, and a cell can topple in the same step in which it received grains. It needs far fewer steps and is several times faster, so it is the best choice for big piles when only the final image matters. Because of the abelian property, both end on exactly the same image.

Can I add grains by clicking on the image?

Yes. While the toppling is paused, or once the sand is stable, click on any cell of the image to drop a grain on it. If the cell reaches 4 grains (or 8), it causes an avalanche, which you can follow with "Next step" or "Resume", and the status above the image shows its size. The grains added by clicking are also in the animation "Step by step, like the preview", at the same steps. A grain dropped away from the center breaks the symmetry of the pile, so the computation then takes about 4 times longer. Changing an option or clicking "Replay" starts again without the clicked grains.

Can I download a video of the sand toppling?

Yes. Once the sand is stable, the "The animation" options create a WebM video or an animated GIF. Choose "Growing pile" to see the fractal appear as grains are added little by little, or "Toppling" to see the avalanches of all the grains dropped at once. The duration and the speed set how fast it goes. Both animations end on exactly the same pile as the image, because the order in which the grains topple doesn't change the result.

Why does creating the growing pile animation take longer?

Every frame of the growing pile is a stable pile, so the sand is stabilized again after each new handful of grains. The grains topple the same number of times in total, but they move in many smaller avalanches, which takes several times longer than dropping them all at once.

Can I use the images commercially?

Yes. The images you generate are yours, and you can use them in wallpapers, prints, presentations or any other project.

Related tools

Game of Life

Game of Life

Create Conway's Game of Life simulations and animations.
Elementary Cellular Automaton

Elementary Cellular Automaton

Draw the 256 elementary cellular automata, like Rule 30, Rule 90 and Rule 110.
Langton's Ant

Langton's Ant

Simulate Langton's ant and its multi-color variants, and download images and videos.
Cyclic Cellular Automaton

Cyclic Cellular Automaton

Create the spiral waves of the cyclic cellular automaton, as images and videos.
Sierpinski Triangle Generator

Sierpinski Triangle Generator

Draw the Sierpinski triangle, by dividing a triangle or by playing the chaos game.
Mandelbrot Set Generator

Mandelbrot Set Generator

Draw the Mandelbrot set, zoom into it with the mouse and download the image.