
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.
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.
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.
| Mode | Description |
|---|---|
| One pile in the center | All 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 piles | Several 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 cell | Every 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 group | The identity element of the sandpile group of the rectangle, computed with two stabilizations. |
Below are all the options you can configure in this abelian sandpile simulator.
| Field | Description |
|---|---|
| Where to drop the sand | Piles 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. |
| Piles | One 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 grains | The 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 piles | The distance, in cells, from the center to the other piles. |
| Width and height of the rectangle | The 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 cell | The number of grains put on every cell of the rectangle in the uniform mode. |
| Neighbors | With 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. |
| Algorithm | Synchronous: 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 grains | All 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. |
| Speed | How 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 click | While the toppling is paused, the number of steps made by each click on "Next step": 1, 10, 100 or 1000. |
| Size of the cell | The size of each cell in pixels, which sets the size of the downloaded image. |
| Margin around the piles | The number of empty cells left around the piles in the image. |
| Palette | The 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 grains | Leaves 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. |
| Animation | Growing 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. |
| Format | A WebM video, or an animated GIF that plays everywhere but makes bigger files and allows fewer frames per second. |
| Duration | How long the sand moves, from 1 to 120 seconds. A shorter animation goes faster. |
| Frames per second | More frames make a smoother animation and a bigger file. GIF only supports 10, 20, 25 and 50 frames per second. |
| Speed | Constant 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 end | How many seconds the stable pile stays on screen at the end of the animation. |
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.





