Last Edit: Jan. 27, 2016, 3:56 a.m.

I've done quite a bit more work on my falling sand game and I'm proud to present the results here.

(Jump to the bottom if you are looking for downloads)

Falling sand games have been around for quite some time and you can find many at http://fallingsandgame.com/sand/. Find out more at wikipedia.

My version runs in python using pygame and has gone through quite a few changes since the last time I shared it. As I was working on it, it started becoming more arbitrary and is now a kind of generic cellular automata engine.

There are a couple other pygame falling sand clones, but they don't run as smoothly as this one seems to. I spent a lot of the development time trying to increase speed and made quite a bit of progress, but I feel like I've hit a wall with the current architecture. I would love to hear any ideas on how to speed things up more. It doesn't run as quickly as the compiled falling sand games you can find on the previously mentioned sites (such as wxsand). I don't know if this is just because of the way I designed the system, or if it is because of python.


I did some tests with pypy (just on the sandbox simulation / no gui or pygame, etc) and saw about a 70% speed improvement on a heavily loaded (~1800 active particles) sandbox. I also tried using the multithreading module on the loop that calls cell.act() for each active cell. That almost crashed my machine. Trying the same thing with number=10 and you can see that some serious rewrites would be needed to make that jive, although I can definitely see it being faster if done properly.

Running With Loops Time
python (2.7) 1000 3.120
python3 1000 3.411
pypy 1000 1.863
multithreading 10 3.163

The game runs in python 2.7 and the only dependencies should be pygame and tkinter. It ran on python3 until I had to make some tweeks to get it working with py2exe for the windows executable. You should be able to get it running on 3 again by coding an absolute path to the theme folder near the top of fallingsand.py

The game also uses easygui and pgu, but these small utilities are bundled together with the software.

Included Automata right now are:

It should be easy to add any other types of cell also.

This video shows paintbrush size changes and framerate changes. Then how temperature affects different elements (lava and stone). Then it shows how water evaporates when it gets hot, and plant growing into water. Then ends with some explosions.

This video shows water running down a hill (made of insulator, so it doesn't affect the water) into a hot spot. The water then evaporates upwards to a cool spot and cycles.

This video shows a "glider gun" from conway's game of life

Keyboard Shortcuts

These are in the fallingsand.py file right inside the main loop.


I recommend the svn option.