reas_processing · wolframCA2D
2-D Totalistic Cellular Automaton (Conway + variants)
Each cell looks at its 8 Moore neighbors and applies a totalistic rule. Five built-in rules are included: Conway's Game of Life (B3/S23), HighLife (B36/S23), Day & Night, Seeds (B2/S), and Brian's Brain (3-state). Live cells age, so sustained activity drifts the palette from 'ink_color' toward the optional 'glow_color', visualizing persistent regions. Periodic re-seeding of small patches every 400 ticks keeps the system active.
Original: https://processing.org/examples/gameoflife
▶ Try the live demo (JS port) ▶ Run reference.py via Pyodide 10 formulas have instant JS ports. The Pyodide path runs the actual Python in your browser — first load is ~6 MB, then instant.
Math essence
nbr = sum(8 rolled neighbors). next_grid[dead & nbr in birth_set | alive & nbr in survive_set] = 1. Brian's Brain uses 3 states with refractory dying. All transitions are fully vectorized via numpy.roll on torus.
Parameters
| Name | Type | Default | Range | Description |
|---|---|---|---|---|
dim | int | 200 | 50–600 | Grid side length (torus topology). |
rule_name | str | conway | — | Rule: conway, highlife, day_and_night, seeds, brians_brain. |
initial_density | float | 0.32 | 0.05–0.9 | Probability a starting cell is alive. |
bg_color | tuple | 240,235,225 | — | |
ink_color | tuple | 30,30,50 | — | |
glow_color | tuple | null | — | Optional hot color for live cells as age accumulates. |
seed | int | null | 0–999999 |
Reference
First 60 lines of reference.py. Full source:
library_external/reas_processing/wolframCA2D/reference.py
from __future__ import annotations
from typing import ClassVar
import numpy as np
LIFE_RULES = {
"conway": (3, (2, 3)),
"highlife": (3, (2, 3)),
"day_and_night": (3, (3, 4), (4, 6), (4, 7)),
"seeds": (2, tuple()),
"brians_brain": (2,),
"wire_world": None,
}
class WolframCA2D:
"""Two-dimensional totalistic cellular automaton.
Each cell on a torus looks at its 8 Moore neighbors and applies a
totalistic rule: a birth rule (number of live neighbors required for
a dead cell to come alive) and a survival rule (number of live
neighbors required to keep a live cell alive). The canonical
Conway's Game of Life is B3/S23, and other classics include
HighLife (B36/S23), Day&Night, Brian's Brain, and Seeds. This is
the standard 2-D CA referenced in Casey Reas's creative-coding
curricula.
"""
family: ClassVar[str] = "reas_processing"
sketch: ClassVar[str] = "wolframCA2D"
def __init__(
self,
dim: int = 200,
rule_name: str = "conway",
initial_density: float = 0.32,
palette: str = "two_color",
bg_color: tuple[int, int, int] = (240, 235, 225),
ink_color: tuple[int, int, int] = (30, 30, 50),
glow_color: tuple[int, int, int] | None = None,
seed: int | None = None,
) -> None:
self.dim = dim
self.rule_name = rule_name
self.initial_density = initial_density
self._palette_mode = palette
self.bg_color = np.array(bg_color, dtype=np.uint8)
self.ink_color = np.array(ink_color, dtype=np.uint8)
self.glow_color = (
np.array(glow_color, dtype=np.uint8) if glow_color is not None else None
)
self._seed = seed
self.reset()
def _build_rule(self, name: str) -> tuple[set[int], set[int]]:
if name == "conway":
return {3}, {2, 3}
if name == "highlife": Try running it locally
The reference implementation is self-contained Python with numpy. Install the package and run:
python library_external/reas_processing/wolframCA2D/reference.py Need help? See Learn for the standard environment setup, or Playground for an in-browser sketchbook.
More from reas · processing
Gray-Scott Reaction-Diffusion
reas_processing · grayScottRD
Two scalar species U and V diffuse on a square grid with rates Du and Dv and react with feed F and kill k.
Lindenmayer L-system + Turtle Rendering
reas_processing · lindenmayer
An axiom string is rewritten by parallel production rules for a fixed number of iterations, then interpreted by a 2-D turtle: 'F' walks forward, '+/-' turn left/right, '['/']' push/pop state.
Particle-Spring Cloth (Verlet + Hooke)
reas_processing · particleSpring
A rectangular grid of free particles is connected by Hooke's-law springs at rest length 'spacing'.
Perlin Streamlines
reas_processing · perlinStreamlines
A 2-D vector field is sampled from one or more octaves of Perlin gradient noise.
Voronoi Diagram from Random Seeds
reas_processing · voronoi
Every pixel on the canvas is colored with the palette color of the seed point closest to it.
Wolfram Elementary 1-D Cellular Automaton
reas_processing · wolframCA1D
Each row of the canvas is one generation of a Wolfram elementary cellular automaton.