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

+ 1
- 1
manager.py View File

@@ -65,7 +65,7 @@ if __name__ == "__main__":
65 65
     m.add(ScrollText(t, "And this twice...", 2))
66 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 69
     m.add(Solid(t, 1.0))
70 70
 
71 71
     m.restart()

Loading…
Cancel
Save