Inheritance diagram of zasim.cagen.neighbourhoods

class zasim.cagen.neighbourhoods.SimpleNeighbourhood(names, offsets, name='')[source]

Bases: zasim.cagen.bases.Neighbourhood

The SimpleNeighbourhood offers named access to any number of neighbouring fields with any number of dimensions.

  • names – A list of names for the neighbouring cells.
  • offsets – A list of offsets for each of the neighbouring cells.
names = ()

The names of neighbourhood fields.

offsets = ()

The offsets of neighbourhood fields.


Adds C and python code to get the neighbouring values and stores them in local variables.


Calculate a bounding box from a set of offsets.


Get the bounding box resulting from step successive reads.

The return value will have an outer tuple with one tuple for each dimension. Each dimension will have a min and a max value.

>>> a = SimpleNeighbourhood(list("lmr"), ((-1,), (0,), (1,)))
>>> a.bounding_box()
((-1, 1),)
>>> a.bounding_box(2)
((-2, 2),)
>>> b = SimpleNeighbourhood(list("ab"), ((-5, 20), (99, 10)))
>>> b.bounding_box()
((-5, 99), (10, 20))
>>> b.bounding_box(10)
((-50, 990), (100, 200))

Get all positions of cells that have the cell at (0, 0) in their neighbourhood.

zasim.cagen.neighbourhoods.ElementaryFlatNeighbourhood(Base=<class 'zasim.cagen.neighbourhoods.SimpleNeighbourhood'>, **kwargs)[source]

This is the neighbourhood used by the elementary cellular automatons.

The neighbours are called l, m and r for left, middle and right.

zasim.cagen.neighbourhoods.VonNeumannNeighbourhood(Base=<class 'zasim.cagen.neighbourhoods.SimpleNeighbourhood'>, **kwargs)[source]

This is the Von Neumann Neighbourhood, in which the cell itself and the left, upper, lower and right neighbours are considered.

The neighbours are called l, u, m, d and r for left, up, middle, down and right respectively.

zasim.cagen.neighbourhoods.MooreNeighbourhood(Base=<class 'zasim.cagen.neighbourhoods.SimpleNeighbourhood'>, **kwargs)[source]

This is the Moore Neighbourhood. The cell and all of its 8 neighbours are considered for computation.

The fields are called lu, u, ru, l, m, r, ld, d and rd for left-up, up, right-up, left, middle, right, left-down, down and right-down respectively.

Previous topic


Next topic

zasim.cagen.border - Handling borders

This Page