資源簡介
二維元胞自動機,馮諾伊曼邊界,可以隨意設置規則,輸出圖像
代碼片段和文件信息
#?-*-?coding:utf-8?-*-
import?numpy?as?np
import?matplotlib.pyplot?as?plt
import?matplotlib.animation?as?animation
import?time
from?mpl_toolkits.mplot3d?import?Axes3D
from?matplotlib.animation?import?FuncAnimation
principle?=‘01011101001001111111110111111111‘
principle0=‘01010111110101010101010101010111‘
principle1=‘00010111110101010101010101010111‘
principle2?=‘00010110110111010100010101011111‘
principle3?=‘01110001011010111001110001000101‘
principle4?=‘01110001011101000011101101010100‘
principle5?=‘01010101010101010101010101010101‘
principle6?=‘01011010101000101011110011111101‘
‘‘‘
定義為馮諾依曼邊界的規則,種類有2^32種
‘‘‘
class?group:
????def?__init__(selflength):
?????????grid?=?np.zeros([lengthlength])
?????????grid[int(length/2)][int(length/2)]?=?1
?????????self.cells?=?grid
?????????self.shape?=?grid.shape
?????????self._length?=?length
????def?genarate(self):
????????N=self._length
????????self.cells?=?np.random.choice([01]N*N?p=[0.3?0.7]).reshape(N?N)
評論
共有 條評論