Life works by applying a few simple rules to a grid of cells which start out in random states.
Very quickly, the initial chaos lessens and the patterns that make life interesting begin to emerge.
The rules of life are simple:
- If a cell is currently on and has 2 or 3 neighbors, it remains on - otherwise it turns off
- If a cell is currently off and has 3 neighbors, it turns on - otherwise it remains off
The grid at the right indicates the cell (C) and the eight neighbors (N) that affect its future.
For cells on the edges with no obvious neighbors, the cell array wraps around to the other side (this creates a torus).
Given the current state of cells, the next generation is computed by looking at each cell and determining its future state according to the rules above.
The result is stored in a separate location to avoid mixing the two generations (since cells depend on the states of other cells which may or may not have been updated yet).
After all cells have been updated, the new generation is displayed and the process begins again.
|
+---+---+---+
| N | N | N |
+---+---+---+
| N | C | N |
+---+---+---+
| N | N | N |
+---+---+---+
|