Awesome cellular automata library created by Borja Esteban.
$ pip install ndautomataThis package is designed in order to create your own automata definitions based on 2 attributes:
- neighbours: List with relative indexes to cell neighbours.
- states: Number possible cell states.
from ndautomata import BaseAutomaton, neighboursclass Automaton(BaseAutomaton):
neighbours = neighbours.regular(ndim=1, r=1)
states = 2Note the automata dimensions are defined with
neighbours.ndim.
After you have defined your automaton, you can instantiate automata passing the initial configuration and the rule to the constructor function. Use the module initializers, based on numpy to generate the required arrays passing the number of states and size.
from ndautomata import initializersrule = initializers.random(states=2, size=[2, 2, 2])
ic = initializers.center(states=2, size=[200])
ca = Automaton(ic, rule)Note the shape of the rule must always be
[states] * neighbours.size.
Plot the cellular automaton using matplotlib or your favorite tool.
import matplotlib.pyplot as pltplt.rcParams["image.cmap"] = "binary"
plt.matshow([next(ca) for _ in range(100)])
plt.show()See examples for more detailed use cases and examples on how to generate some plots.
Fork the repository, pick one of the issues at the issues and create a Pull request.

