|
@@ -11,7 +11,7 @@ import time
|
11
|
11
|
import random
|
12
|
12
|
|
13
|
13
|
class GameOfLife:
|
14
|
|
- def __init__(self, g, f = 20, c1 = (255, 255, 255), c2 = (0, 0, 0), t = 20.0, rc = False):
|
|
14
|
+ def __init__(self, g, f = 20, c1 = (255, 255, 255), c2 = (0, 0, 0), t = 20.0, rc = None):
|
15
|
15
|
self.gui = g
|
16
|
16
|
self.interval = 1.0 / f
|
17
|
17
|
self.setColors(c1, c2)
|
|
@@ -24,18 +24,19 @@ class GameOfLife:
|
24
|
24
|
self.data = self.init()
|
25
|
25
|
self.start = time.time()
|
26
|
26
|
self.last = time.time()
|
|
27
|
+ self.lastColor = time.time()
|
27
|
28
|
self.done = False
|
28
|
29
|
|
29
|
|
- if self.randomizeColors:
|
|
30
|
+ if self.randomizeColors != None:
|
30
|
31
|
self.randomize()
|
31
|
32
|
|
32
|
|
- def setColors(self, c1, c2):
|
|
33
|
+ def setColors(self, c1 = (255, 255, 255), c2 = (0, 0, 0)):
|
33
|
34
|
self.colorFG = c1
|
34
|
35
|
self.colorBG = c2
|
35
|
36
|
|
36
|
37
|
def randomize(self):
|
37
|
|
- c1 = (random.randrange(0, 256), random.randrange(0, 256), random.randrange(0, 256))
|
38
|
|
- c2 = (random.randrange(0, 128), random.randrange(0, 128), random.randrange(0, 128))
|
|
38
|
+ c1 = (random.randrange(0, 16) << 4, random.randrange(0, 16) << 4, random.randrange(0, 16) << 4)
|
|
39
|
+ c2 = (random.randrange(0, 16) << 0, random.randrange(0, 16) << 0, random.randrange(0, 16) << 0)
|
39
|
40
|
self.setColors(c1, c2)
|
40
|
41
|
|
41
|
42
|
def init(self):
|
|
@@ -105,6 +106,11 @@ class GameOfLife:
|
105
|
106
|
self.last = time.time()
|
106
|
107
|
self.step()
|
107
|
108
|
|
|
109
|
+ if (self.randomizeColors != None) and (self.randomizeColors != True):
|
|
110
|
+ if (time.time() - self.lastColor) > self.randomizeColors:
|
|
111
|
+ self.lastColor = time.time()
|
|
112
|
+ g.randomize()
|
|
113
|
+
|
108
|
114
|
for x in range(0, self.gui.width):
|
109
|
115
|
for y in range(0, self.gui.height):
|
110
|
116
|
if self.data[x][y]:
|
|
@@ -122,15 +128,11 @@ if __name__ == "__main__":
|
122
|
128
|
from test import TestGUI
|
123
|
129
|
t = TestGUI()
|
124
|
130
|
|
125
|
|
- g = GameOfLife(t)
|
126
|
|
-
|
127
|
|
- # start out with random colors
|
128
|
|
- g.randomize()
|
|
131
|
+ g = GameOfLife(t, 20, (255, 255, 255), (0, 0, 0), 20.0, 2.0)
|
129
|
132
|
|
130
|
133
|
def helper():
|
131
|
134
|
if g.finished():
|
132
|
135
|
g.restart()
|
133
|
|
- g.randomize()
|
134
|
136
|
g.draw()
|
135
|
137
|
|
136
|
138
|
t.debug_loop(helper)
|