>Fallingsand2
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.
Update
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:
- Falling Sand (elements.py)
- Conways' Game of Life (conway.py)
- WireWorld (wireworld.py)
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
- F5/F9 are quicksave and quickload respectively.
- 1-7 load some different elements
- +, - increase/decrease the paintbrush size
- Mouse scrollwheel alone changes the brush size
- Mouse scrollwheel plus ctrl changes the temperature.
- p pauses/unpauses the sim
- g toggles gridlines
These are in the fallingsand.py file right inside the main loop.
Downloads
- Source Code:
- grab the latest with SVN:
- svn checkout http://svn.danomagnum.com/svn/fallingsand
- tar.gz: fallingsand.tar.gz
- Browse: http://svn.danomagnum.com/svn/fallingsand
- Windows Binary:
- made with py2exe: fallingsand.zip (Note: this version lst updated on 2014-04-27)
Updates
- Changed conway and wireworld cells to subclass off of Element instead of Automata. This lets them not break things when they interact with falling sand particles.
- Added a clear function and button to the sandbox.
- Added toggle-able gridlines and a mouse position display.
- Added a toggle-able cursor display
- changed the default renderer to use scale2x which gives less pixelated visuals.