Giter Site home page Giter Site logo

sandpile's Introduction

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

Required packages

This module requires matplotlib, numpy and PIL to be installed.

pip3 install matplotlib numpy Pillow

Usage

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.

Construct a sandpile:
from sandpile import Sandpile
pile = Sandpile(options)

options may contain:

  • rows - height of sandpile
  • cols - width of sandpile
  • max_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]])
Add sand to sandpile:
pile.set_sand(x, y, number)

where x and y - coordinates of sandpile grid, number - count of sand grains

Run the model:
pile.run()
Visualisations:

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 want
  • filename - 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

Program example

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")

Examples

2^18 grains

Fractal in a 401x401 lattice created from an initial 2^18 (262144) grains in the center

2^20 grains

Fractal in a 801x801 lattice created from an initial 2^20 (1048576) grains in the center

sandpile's People

Contributors

kivyfreakt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.