A Python/Pygame implementation of the famous cellular automata.
Table of Contents
Conways game of life is a cellular automata created by John Horton Conway. The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which (at any given time) is in one of two possible states, "live" (alternatively "on") or "dead" (alternatively "off"). Every cell interacts with its eight neighbours, which are the cells that are directly horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
These simple rules are enough to consider the game as "Turing Complete" (relevant xkcd).
The ConwayLife Wiki Pattern Archive has a large collection of various patterns to play with that can be downloaded into the ./patterns directory. Some patterns may be larger than the default grid size, this can be increased within the config.py if necessary.
This project was created in 2 weeks as a uni assignment and as such will see minimal development, this was made mostly for fun and will stay as such.
-
Clone the repo
git clone https://github.com/Abaan404/conway-python
-
Install the required Python packages
pip3 install -r requirements.txt
-
Run the script
python3 main.py # tested with python 3.10
Following are the default keybindings. There are more config options within the config.py file to tinker with.
| Name | Keybind | Description |
|---|---|---|
| Draw/Erase (Toggle) | Left Mouse Button | Toggle a cell on the grid |
| Zoom In/Out | Mouse Scroll Wheel | Zoom in/out of the grid |
| Move Highlight | W/A/S/D | Move the current highlight on the grid |
| Toggle Highlight | Enter | Toggle the current highlighted cell |
| Run | R | Run the simulation |
| Step | E | Step through each generation |
| Reset | Q | Reset the grid |
| Cycle Patterns | Left/Right | Cycle through available patterns |
| Debug | F3 | Display debug info |
- The amazing video by Rational Animations which had inspired me to make this project.
- Fonts by JetBrains Mono.