pyCA.ca2d module

Two-dimensional outer-totalistic cellular automata.

An outer-totalistic rule updates each cell from its own value and the sum of its eight (Moore) neighbors, nothing more. The family is conventionally named in B/S notation: B lists the neighbor counts at which a dead cell is born, S the counts at which a live cell survives. Conway’s Game of Life is B3/S23 — born with exactly three neighbors, surviving with two or three — and remains the canonical inhabitant of the family.

class pyCA.ca2d.CA2D(births, survivals, state=None, shape=(128, 128), fill=0.5, memory=256, rng=None)[source]

Bases: object

An outer-totalistic cellular automaton on a periodic 2d lattice.

Parameters:
  • births (sequence of int) – Neighbor counts (0-8) at which a dead cell becomes alive.

  • survivals (sequence of int) – Neighbor counts (0-8) at which a live cell stays alive.

  • state (array_like of 0s and 1s, optional) – Initial 2d state. If omitted, a random state of the given shape is drawn with density fill.

  • shape (tuple of int, optional) – Lattice shape used when state is omitted (default (128, 128)).

  • fill (float, optional) – Live-cell density of the random initial state (default 0.5).

  • memory (int, optional) – Number of past states retained (default 256).

  • rng (numpy.random.Generator, optional) – Random source; defaults to numpy.random.default_rng().

Examples

>>> from pyCA import CA2D
>>> life = CA2D.life((64, 64))
>>> life.run(100)
>>> life.population
...
evolve()[source]

Advance the automaton one time step.

history()[source]

The remembered history as a (time, rows, columns) array.

classmethod life(shape=(128, 128), state=None, **kwargs)[source]

Conway’s Game of Life, B3/S23.

play(interval=30)[source]

Open a live display; close the window to stop.

Parameters:

interval (int, optional) – Milliseconds between frames (default 30).

property population

Number of live cells in the current state.

run(steps)[source]

Advance the automaton steps time steps.