
This free online abelian sandpile generator simulates 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.
Choose the colors of each number of grains and download the result as a PNG image. 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: this tool topples each cell with all its grains at once, and it only computes 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 generator.
| 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. |
| 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. With 8 neighbors, the 4 colors 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. |
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, 131072 grains take less than a second, 524288 grains take a few seconds and a million grains take around 40 seconds. 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 use the images commercially?Yes. The images you generate are yours, and you can use them in wallpapers, prints, presentations or any other project.





