一个模拟简单细胞自动机的小程序包。
pycells的Python项目详细描述
pyCells
最近很无聊的时候,我又开始玩模拟细胞自动机了。 但是为了比平时多挑战一下自己,我设置了三个具体的限制,让这件事变得更加困难 比我以前习惯的:
- 模拟函数应该能够处理n维规则和状态。在
- 规则应该是整数。在
- 状态应该用整数表示,利用整个状态由 可以展平的n维布尔数组。在
我给自己增加的另一个负担是实施多种独特风格的规则:
- 基于模式的规则,例如流行的110或30。在
- 邻居计数规则,如康威的生活游戏。在
使用
从PyPi
- 运行
pip install pycells
- 运行
pycells
并检查您有哪些选项
来源
- 克隆此回购
- 使用python
> 3.7
和./requirements.txt
设置virtualenv - 运行
python simulate.py
我实现了一个cli和一个基于文件的模拟配置系统。cli是结构化的 具体如下:
$ python simulation.py
Usage: simulate.py [OPTIONS]
Simulate n-dimensional cellular automata using some of the most common
methods.
Options:
-p, --preset [conway|elementary]
simulation preset to use
-f, --file FILENAME file to load simulation config from
-d, --dimensions TEXT dimensions of the simulation, format:
N[xN[xN[...]]
-m, --method [count|pattern] simulation method
-r, --rule INTEGER rule to simulate
-i, --iterations INTEGER iterations to simulate
-n, --neighborhood-radius INTEGER
neighborhood radius to use
-o, --out FILE path to save the output to
--initial-state INTEGER initial simulation state
--skip-initial-state skip the initial state
--parallelize enabled parallel calculation of cells per
state transition
--scaling INTEGER scaling to apply to output
--format [gif|png|npy|txt] format to output as, this skips the default
which is to simply use the most suitable for
the given number of dimensions
--help Show this message and exit.
要使用基于文件的配置选项,只需编写一个包含所有
必要的参数。对于一些示例,请查看./examples
目录。
如果你想在这些文件中写二进制数,我已经在yaml解析器中添加了两个标记
!b
和{
使用预定义的预置也是类似的,使用它们只需使用-p
选项
并填写其余未定义的参数:
python simulate.py -p conway -d 64x64 -i 32
通知
虽然这个实现现在可以处理n维状态,但我只实现了
一维和二维自动机的图形可视化。如果你想创建你自己的可视化
您可以指定一种基于文本的格式(例如txt
,npy
)。在
示例
对于更多示例,请查看呈现的输出here。在
- 项目
标签: