瀏覽代碼

scrollers can scroll by more than 1px

Thomas Buck 1 年之前
父節點
當前提交
0ebcdf1ba6
共有 2 個檔案被更改,包括 8 行新增4 行删除
  1. 2
    2
      draw.py
  2. 6
    2
      life.py

+ 2
- 2
draw.py 查看文件

@@ -86,7 +86,7 @@ class DrawText:
86 86
         return w
87 87
 
88 88
 class ScrollText:
89
-    def __init__(self, g, t, i = 1, s = 100):
89
+    def __init__(self, g, t, i = 1, s = 50):
90 90
         self.gui = g
91 91
         self.drawer = DrawText(self.gui)
92 92
         self.text = t
@@ -106,8 +106,8 @@ class ScrollText:
106 106
 
107 107
     def draw(self):
108 108
         if (time.time() - self.last) > self.speed:
109
+            self.offset += (time.time() - self.last) / self.speed
109 110
             self.last = time.time()
110
-            self.offset = (self.offset + 1)
111 111
             if self.offset >= self.width:
112 112
                 self.offset = -self.gui.width
113 113
                 self.count += 1

+ 6
- 2
life.py 查看文件

@@ -60,6 +60,9 @@ class GameOfLife:
60 60
                     continue
61 61
                 if self.alive(data, x + xOff, y + yOff):
62 62
                     c += 1
63
+                    if c == 4:
64
+                        # 4 or more is not interesting for us
65
+                        break
63 66
         return c
64 67
 
65 68
     def step(self):
@@ -113,8 +116,9 @@ if __name__ == "__main__":
113 116
     g = GameOfLife(t)
114 117
 
115 118
     def helperRestart():
116
-        c = (random.randrange(0, 256), random.randrange(0, 256), random.randrange(0, 256))
117
-        g.setColors(c, (0, 0, 0))
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)
118 122
 
119 123
     # start out with random colors
120 124
     helperRestart()

Loading…
取消
儲存