Much has been written about the cellular automaton Life invented by the Cambridge mathematician John Conway.
The idea of Life is very simple. One has cells on a grid of squares, and each cell can be either alive or dead. After each timestep, a cell will be alive if one of the following is true:
- It had three live neighbours on the previous timestep
- It had two live neighbours, and was itself alive, on the previous timestep
(Each cell is considered to have eight neighbouring cells.)
These rules were inspired from biology, in that either overpopulation or isolation leads to death, and optimal conditions lead to population increase. Surprisingly complicated behaviour arises from such simple rules, and the example code given starts with just five cells being alive, but they cause a colony to form which evolves for over a thousand timesteps and spreads to a width of around 100 cells, before finally settling down to a steady state.
Conway did not use a computer initially, but rather used counters on a Go board and evolved patterns by hand.
There are many programs for running this automaton available on the web, some written to run in browsers, some written in python, some highly optimised for speed. In some ways it is pointless to try to add to them, but, never the less, this python version of Life is offered as an example of what can be knocked together over a weekend, and still be quite useable. It uses the tk toolkit, so should work fine on all platforms including MacOS.
It can load patterns written in the rle format used by sites such as conwaylife.com/wiki, it can pad a pattern with blank cells once loaded, and it allows one to edit the grid once the run is paused. It has a variable delay, and reports the number of iterations, or frames, per second achieved.
The screenshot above was obtained by downloading the rle file for the Gosper glider gun from Conwaylife.com (also cached here), loading it, and then setting the grid size to 80 before pressing start. Note that these rle files are nothing to do with image files with the same extension, and so need downloading not passing to an image viewer.
Writing the above example in python resulted in an example of vectorisation giving a speed-up of well over twenty times, so I also document the development of this code.
Other ideas for interesting starting positions can be found on Wikipedia. The position that this code runs automatically is the R-pentomino, which runs for about 1100 timesteps before settling into a periodic configuration.
Much better optimised, and more fully featured, alternatives include LifeViewer, which is written in HTML5, and Golly, which is distributed as source and binaries for MacOS, Windows and Linux. It may also be available on many Linux distributions via
sudo apt-get install golly