-
Notifications
You must be signed in to change notification settings - Fork 0
/
conwayCustom.py
executable file
·95 lines (84 loc) · 2.66 KB
/
conwayCustom.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import random
from apcs import *
map = []
size = [100,100]
scale = 5
Window.size(size[0]*scale, size[1]*scale)
#Window.size(500,500)
for i in range(size[0]):
crow = []
for n in range(size[1]):
crow.append(False)
#bool(random.getrandbits(1))
map.append(crow)
def main():
bgID = Window.out.background("white")
mapID = []
if Window.mouse.clicked():
x,y = int(Window.mouse.getX()/scale), int(Window.mouse.getY()/scale)
r = 5
map[y][x] = not(map[y][x])
"""
for l in range(-5,5):
for i in range(-5,5):
ny = y+l
nx = x+i
print(nx,ny)
if ny >= 0 and ny < size[1] and nx >= 0 and nx < size[0]:
#if Window.key.pressed("space"):
#map[ny][nx] = True
#else:
map[ny][nx] = False
"""
rc = 0
for r in map:
ic = 0
crow = []
for i in r:
count = 0
if not rc == 0:
if not ic == 0:
if map[rc - 1][ic - 1]:
count += 1
if not ic == size[0] - 1:
if map[rc - 1][ic + 1]:
count += 1
if map[rc - 1][ic]:
count += 1
if not rc == size[1] - 1:
if not ic == 0:
if map[rc + 1][ic - 1]:
count += 1
if not ic == size[0] - 1:
if map[rc + 1][ic + 1]:
count += 1
if map[rc + 1][ic]:
count += 1
if not ic == 0:
if map[rc][ic - 1]:
count += 1
if not ic == size[0] - 1:
if map[rc][ic + 1]:
count += 1
if Window.key.pressed("space"):
if map[rc][ic]:
if count < 2:
map[rc][ic] = False
if count == 2 or count == 3:
map[rc][ic] = True
if count > 3:
map[rc][ic] = False
else:
if count == 3:
map[rc][ic] = True
if i:
Window.out.color("black")
else:
Window.out.color("white")
crow.append(Window.out.square(ic*scale+(scale/2), rc*scale+(scale/2), scale))
#crow.append(Window.out.circle(ic * scale + (scale/2), rc * scale + (scale/2), scale)
ic += 1
mapID.append(crow)
rc += 1
Window.frame(main)
Window.start()