-
Notifications
You must be signed in to change notification settings - Fork 0
/
cellularAutomata_gh_py
81 lines (65 loc) · 2.85 KB
/
cellularAutomata_gh_py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
INPUTS:
int x
int y
"""
import Rhino.Geometry as rg
listOfLists = []
# define first generation
firstGeneration = []
for i in range (0,x):
firstGeneration.append(0)
firstGeneration[int(x/2)] = 1 # overwrite one value
list_0 = []
for i in range(0,x):
list_0.append(firstGeneration[i])
for j in range (0,y):
# compute next generation
list_1 = []
for i in range(0,x):
list_1.append(list_0[i])
for i in range (1,x-1):
# RULE 90
#---------------x----------------x------------------x
if list_0[i-1]==1 and list_0[i]==1 and list_1[i+1]==1: list_1[i]=0 #1
if list_0[i-1]==1 and list_0[i]==1 and list_1[i+1]==0: list_1[i]=1 #2
if list_0[i-1]==1 and list_0[i]==0 and list_1[i+1]==1: list_1[i]=0 #3
if list_0[i-1]==1 and list_0[i]==0 and list_1[i+1]==0: list_1[i]=1 #4
if list_0[i-1]==0 and list_0[i]==1 and list_1[i+1]==1: list_1[i]=1 #5
if list_0[i-1]==0 and list_0[i]==1 and list_1[i+1]==0: list_1[i]=0 #6
if list_0[i-1]==0 and list_0[i]==0 and list_1[i+1]==1: list_1[i]=1 #7
if list_0[i-1]==0 and list_0[i]==0 and list_1[i+1]==0: list_1[i]=0 #8
"""
# RULE 110
#---------------x----------------x------------------x
if list_0[i-1]==1 and list_0[i]==1 and list_1[i+1]==1: list_1[i]=0 #1
if list_0[i-1]==1 and list_0[i]==1 and list_1[i+1]==0: list_1[i]=1 #2
if list_0[i-1]==1 and list_0[i]==0 and list_1[i+1]==1: list_1[i]=1 #3
if list_0[i-1]==1 and list_0[i]==0 and list_1[i+1]==0: list_1[i]=0 #4
if list_0[i-1]==0 and list_0[i]==1 and list_1[i+1]==1: list_1[i]=1 #5
if list_0[i-1]==0 and list_0[i]==1 and list_1[i+1]==0: list_1[i]=1 #6
if list_0[i-1]==0 and list_0[i]==0 and list_1[i+1]==1: list_1[i]=1 #7
if list_0[i-1]==0 and list_0[i]==0 and list_1[i+1]==0: list_1[i]=0 #8
"""
"""
# RULE 30
#---------------x----------------x------------------x
if list_0[i-1]==1 and list_0[i]==1 and list_1[i+1]==1: list_1[i]=0 #1
if list_0[i-1]==1 and list_0[i]==1 and list_1[i+1]==0: list_1[i]=0 #2
if list_0[i-1]==1 and list_0[i]==0 and list_1[i+1]==1: list_1[i]=0 #3
if list_0[i-1]==1 and list_0[i]==0 and list_1[i+1]==0: list_1[i]=1 #4
if list_0[i-1]==0 and list_0[i]==1 and list_1[i+1]==1: list_1[i]=1 #5
if list_0[i-1]==0 and list_0[i]==1 and list_1[i+1]==0: list_1[i]=1 #6
if list_0[i-1]==0 and list_0[i]==0 and list_1[i+1]==1: list_1[i]=1 #7
if list_0[i-1]==0 and list_0[i]==0 and list_1[i+1]==0: list_1[i]=0 #8
"""
listOfLists.append(list_1)
list_0 = list_1
listOfLists.insert(0,firstGeneration)
listOfLists = listOfLists[ : -1]
listOfLists.reverse()
flatList = []
for i in range (0,y):
for j in range (0, x):
flatList.append(listOfLists[i][j])
a = flatList