Conway's Game of Life
by subpixel
Based on Conway.pde by Mike Davis
At each iteration, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if by needs caused by underpopulation.
- Any live cell with more than three live neighbours dies, as if by overcrowding.
- Any live cell with two or three live neighbours lives, unchanged, to the next generation.
- Any tile with exactly three live neighbours cells will be populated with a living cell.
Controls
- Mouse click/drag - make the cell at the mouse position "alive"
- [space] - pause/unpause the simulation
- [n] - new world (empty)
- [g] - set up a grid (click in it or press [r] to kick it off!)
- [a] - add a random cell (birth)
- [d] - kill a random cell (death)
- [1234567890] - grow new cells (1 few, 5 some, 9 many, 0 most)
- [qwertyuiop] - kill off cells (q few, t some, o many, p most)
Optimisation
Optimisations made reduce the time taken to render each frame by around 50% or more compared to the original on my machine (2GHz Pentium-M based laptop). eg, for a 1300x1000 world, the original code (with a few lines added for the time calculation, and the size() and frameRate() call parameters increased) renders each iteration in around 170ms; the optimised program takes only around 80ms (when there are relatively fewer births and deaths; when there are a lot of births and deaths the time can get much higher, but this usually only lasts a few iterations until the number of births and deaths lowers again.
See the program source for details.
Source code: Conway_mod_by_spxl
Built with Processing