回答編集履歴
1
追記
test
CHANGED
@@ -22,4 +22,116 @@
|
|
22
22
|
|
23
23
|
`AttributeError: 'points' object has no attribute '_size'`
|
24
24
|
|
25
|
-
が発生してしまいます
|
25
|
+
が発生してしまいます。
|
26
|
+
|
27
|
+
ほかエラーをいくつか潰してみましたが、死滅セルの更新ができず、まともに動作させることはできませんでした。
|
28
|
+
|
29
|
+
```Python
|
30
|
+
|
31
|
+
from vpython import *
|
32
|
+
|
33
|
+
from IPython.display import display
|
34
|
+
|
35
|
+
from numpy import zeros
|
36
|
+
|
37
|
+
import random
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
scene = display(width = 500 , height = 500 , title = 'Game of Life')
|
42
|
+
|
43
|
+
cell = zeros((50 , 50)); cellu = zeros((50 , 50))
|
44
|
+
|
45
|
+
curve( pos =
|
46
|
+
|
47
|
+
[(-49 , -49, 0) , (-49 , 49, 0) , (49 , 49, 0) , (49 , -49, 0) , (-49 , -49, 0)] , color = color.white) # ***
|
48
|
+
|
49
|
+
boxes = points(shape = 'square' , color = color.cyan)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def drawcells(ce):
|
54
|
+
|
55
|
+
boxes.empty() # ***
|
56
|
+
|
57
|
+
for j in range(0 , 50):
|
58
|
+
|
59
|
+
for i in range(0 , 50): # ***
|
60
|
+
|
61
|
+
if ce[i , j] == 1:
|
62
|
+
|
63
|
+
xx = 2*i - 50
|
64
|
+
|
65
|
+
yy = 2*j - 50
|
66
|
+
|
67
|
+
boxes.append(pos = (xx , yy, 0)) # ***
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
def initial():
|
72
|
+
|
73
|
+
for j in range(20 , 28):
|
74
|
+
|
75
|
+
for i in range(20 , 28):
|
76
|
+
|
77
|
+
r= int(random.random() * 2)
|
78
|
+
|
79
|
+
cell[j , i] = r
|
80
|
+
|
81
|
+
return cell
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def gameoflife(call):
|
86
|
+
|
87
|
+
for i in range(1 , 49):
|
88
|
+
|
89
|
+
for j in range(1 , 49):
|
90
|
+
|
91
|
+
sum1 = cell[i-1 , j-1] + cell[i , j-1] + cell[i+1 , j-1]
|
92
|
+
|
93
|
+
sum2 = cell[i-1 , j] + cell[i+1 , j] + cell[i-1 , j+1] + cell[i , j+1] + cell[i+1 , j+1]
|
94
|
+
|
95
|
+
alive = sum1 + sum2
|
96
|
+
|
97
|
+
if cell[i , j] == 1:
|
98
|
+
|
99
|
+
if alive == 2 or alive == 3:
|
100
|
+
|
101
|
+
cellu[i , j] = 1
|
102
|
+
|
103
|
+
if alive > 3 or alive < 2:
|
104
|
+
|
105
|
+
cellu[i , j] = 0
|
106
|
+
|
107
|
+
if cell[i , j] == 0:
|
108
|
+
|
109
|
+
if alive == 3:
|
110
|
+
|
111
|
+
cellu[i , j] = 1
|
112
|
+
|
113
|
+
else:
|
114
|
+
|
115
|
+
cellu[i , j] = 0
|
116
|
+
|
117
|
+
alive = 0
|
118
|
+
|
119
|
+
return cellu
|
120
|
+
|
121
|
+
temp = initial()
|
122
|
+
|
123
|
+
drawcells(temp)
|
124
|
+
|
125
|
+
while True:
|
126
|
+
|
127
|
+
rate(6)
|
128
|
+
|
129
|
+
cell = temp
|
130
|
+
|
131
|
+
temp = gameoflife(cell)
|
132
|
+
|
133
|
+
drawcells(cell)
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
![イメージ説明](f485673487a7b4f6dd8e13a306bdbbb0.png)
|