Multidimensional cellular automata in Python.
Project description
ndAutomata
Awesome cellular automata library created by Borja Esteban.
Install it from PyPI
$ pip install ndautomata
Usage
This 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, neighbours
class Automaton(BaseAutomaton):
neighbours = neighbours.regular(ndim=1, r=1)
states = 2
Note 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 initializers
rule = 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 plt
plt.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.
Development
Fork the repository, pick one of the issues at the issues and create a Pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ndautomata-0.1.2.tar.gz
.
File metadata
- Download URL: ndautomata-0.1.2.tar.gz
- Upload date:
- Size: 123.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b67e89df1d48a16b3f920c5ebc992451839295572de885d8a11c53c272161fcb |
|
MD5 | 1bf84995386a6f6e62f62b9877a35e28 |
|
BLAKE2b-256 | e7395a1b74956e608a205054533d729fe66f36644ddbb38d59449d4c5e1b5bde |
File details
Details for the file ndautomata-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: ndautomata-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcdfc6c4b5eef785a743acc8e386438c1a3d9c17397d3b3479e36b16e680deba |
|
MD5 | d8a01e36a2f6a82105ca101054e9043a |
|
BLAKE2b-256 | 20b46fe38a86ee35642d3d573f8c2da297803134f5110277404fd1eb6823aa72 |