This is a project in a course of chaos theory at Lund University, Sweden. We took the liberty of using the code we found from this original project by kivyfreakt: https://github.com/kivyfreakt/sandpile
Python implementation of the Sandpile Model
The Abelian sandpile model, also known as the Bak–Tang–Wiesenfeld model, was the first discovered example of a dynamical system displaying self-organized criticality.
To know more read https://en.wikipedia.org/wiki/Abelian_sandpile_model
This module requires matplotlib, numpy and PIL to be installed.
pip3 install matplotlib numpy Pillow
To run the model, choose the simulation parameters and run the script sandpile/example.py. Important parameters are the grid size and the number of grains to be dropped.
The main model methods can be found at sandpile/sandpile.py.
from sandpile import Sandpile
pile = Sandpile(options)
options
may contain:
rows
- height of sandpilecols
- width of sandpilemax_sand
- max count of sandpile grains
It gives you a zero sandpile
Also you can create sandpile from array, if you give array to constructor
from sandpile import Sandpile
pile = Sandpile([[0,1,0],[1,0,1],[0,1,0]])
pile.set_sand(x, y, number)
where x
and y
- coordinates of sandpile grid, number
- count of sand grains
pile.run()
If you would like to plot sandpile and show it, you can use
pile.show(options)
options
may contain:
save
- true = if you want save picture, false = if don't wantfilename
- name of the file, where would be picture of sandpile
If you just want to save the picture , then use
pile.save(filename)
where filename
- name of the file, where would be picture of sandpile
You can find this example in /sandpile/example.py
from sandpile import Sandpile
pile = Sandpile(rows = 201, cols = 201)
pile.set_sand(100, 100, 2**16)
pile.run()
pile.show(save = True, filename = "2^16 grains(1).png")
pile.save(filename = "2^16 grains(2).png")
Fractal in a 401x401 lattice created from an initial 2^18 (262144) grains in the center
Fractal in a 801x801 lattice created from an initial 2^20 (1048576) grains in the center