Browse Source

gol random colors possible everywhere

Thomas Buck 1 year ago
parent
commit
12e7794a47
2 changed files with 13 additions and 9 deletions
  1. 12
    8
      life.py
  2. 1
    1
      manager.py

+ 12
- 8
life.py View File

11
 import random
11
 import random
12
 
12
 
13
 class GameOfLife:
13
 class GameOfLife:
14
-    def __init__(self, g, f = 20, c1 = (255, 255, 255), c2 = (0, 0, 0), t = 20.0):
14
+    def __init__(self, g, f = 20, c1 = (255, 255, 255), c2 = (0, 0, 0), t = 20.0, rc = False):
15
         self.gui = g
15
         self.gui = g
16
         self.interval = 1.0 / f
16
         self.interval = 1.0 / f
17
         self.setColors(c1, c2)
17
         self.setColors(c1, c2)
18
         self.timeout = t
18
         self.timeout = t
19
+        self.randomizeColors = rc
19
         random.seed()
20
         random.seed()
20
         self.restart()
21
         self.restart()
21
 
22
 
25
         self.last = time.time()
26
         self.last = time.time()
26
         self.done = False
27
         self.done = False
27
 
28
 
29
+        if self.randomizeColors:
30
+            self.randomize()
31
+
28
     def setColors(self, c1, c2):
32
     def setColors(self, c1, c2):
29
         self.colorFG = c1
33
         self.colorFG = c1
30
         self.colorBG = c2
34
         self.colorBG = c2
31
 
35
 
36
+    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))
39
+        self.setColors(c1, c2)
40
+
32
     def init(self):
41
     def init(self):
33
         data = []
42
         data = []
34
         for x in range(0, self.gui.width):
43
         for x in range(0, self.gui.width):
115
 
124
 
116
     g = GameOfLife(t)
125
     g = GameOfLife(t)
117
 
126
 
118
-    def helperRestart():
119
-        c1 = (random.randrange(0, 256), random.randrange(0, 256), random.randrange(0, 256))
120
-        c2 = (random.randrange(0, 128), random.randrange(0, 128), random.randrange(0, 128))
121
-        g.setColors(c1, c2)
122
-
123
     # start out with random colors
127
     # start out with random colors
124
-    helperRestart()
128
+    g.randomize()
125
 
129
 
126
     def helper():
130
     def helper():
127
         if g.finished():
131
         if g.finished():
128
             g.restart()
132
             g.restart()
129
-            helperRestart()
133
+            g.randomize()
130
         g.draw()
134
         g.draw()
131
 
135
 
132
     t.debug_loop(helper)
136
     t.debug_loop(helper)

+ 1
- 1
manager.py View File

65
     m.add(ScrollText(t, "And this twice...", 2))
65
     m.add(ScrollText(t, "And this twice...", 2))
66
     m.add(Solid(t, 1.0))
66
     m.add(Solid(t, 1.0))
67
 
67
 
68
-    m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0))
68
+    m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
69
     m.add(Solid(t, 1.0))
69
     m.add(Solid(t, 1.0))
70
 
70
 
71
     m.restart()
71
     m.restart()

Loading…
Cancel
Save