소스 검색

gol faster and random colors. remove broken weather tests.

Thomas Buck 1 년 전
부모
커밋
f8d821d9d2
4개의 변경된 파일18개의 추가작업 그리고 85개의 파일을 삭제
  1. 1
    2
      draw.py
  2. 15
    4
      life.py
  3. 2
    6
      manager.py
  4. 0
    73
      weather.py

+ 1
- 2
draw.py 파일 보기

@@ -85,13 +85,12 @@ class ScrollText:
85 85
 
86 86
     def draw(self):
87 87
         if (time.time() - self.last) > self.speed:
88
+            self.last = time.time()
88 89
             self.offset = (self.offset + 1)
89 90
             if self.offset >= self.width:
90 91
                 self.offset = -self.gui.width
91 92
                 self.count += 1
92 93
 
93
-            self.last = time.time()
94
-
95 94
         self.drawer.text(self.text, self.offset)
96 95
 
97 96
 if __name__ == "__main__":

+ 15
- 4
life.py 파일 보기

@@ -4,11 +4,10 @@ import time
4 4
 import random
5 5
 
6 6
 class GameOfLife:
7
-    def __init__(self, g, f = 20, c1 = (255, 255, 255), c2 = (0, 0, 0), t = 30.0):
7
+    def __init__(self, g, f = 20, c1 = (255, 255, 255), c2 = (0, 0, 0), t = 20.0):
8 8
         self.gui = g
9 9
         self.interval = 1.0 / f
10
-        self.colorFG = c1
11
-        self.colorBG = c2
10
+        self.setColors(c1, c2)
12 11
         self.timeout = t
13 12
         random.seed()
14 13
         self.restart()
@@ -19,6 +18,10 @@ class GameOfLife:
19 18
         self.last = time.time()
20 19
         self.done = False
21 20
 
21
+    def setColors(self, c1, c2):
22
+        self.colorFG = c1
23
+        self.colorBG = c2
24
+
22 25
     def init(self):
23 26
         data = []
24 27
         for x in range(0, self.gui.width):
@@ -80,8 +83,8 @@ class GameOfLife:
80 83
 
81 84
     def draw(self):
82 85
         if (time.time() - self.last) > self.interval:
83
-            self.step()
84 86
             self.last = time.time()
87
+            self.step()
85 88
 
86 89
         for x in range(0, self.gui.width):
87 90
             for y in range(0, self.gui.height):
@@ -102,9 +105,17 @@ if __name__ == "__main__":
102 105
 
103 106
     g = GameOfLife(t)
104 107
 
108
+    def helperRestart():
109
+        c = (random.randrange(0, 256), random.randrange(0, 256), random.randrange(0, 256))
110
+        g.setColors(c, (0, 0, 0))
111
+
112
+    # start out with random colors
113
+    helperRestart()
114
+
105 115
     def helper():
106 116
         if g.finished():
107 117
             g.restart()
118
+            helperRestart()
108 119
         g.draw()
109 120
 
110 121
     t.debug_loop(helper)

+ 2
- 6
manager.py 파일 보기

@@ -22,19 +22,18 @@ class Manager:
22 22
         if self.screens[self.index][1] == None:
23 23
             # let screen decide when it is done
24 24
             if self.screens[self.index][0].finished():
25
-                self.index = (self.index + 1) % len(self.screens)
26 25
                 self.lastTime = time.time()
26
+                self.index = (self.index + 1) % len(self.screens)
27 27
                 self.screens[self.index][0].restart()
28 28
         else:
29 29
             # use given timeout
30 30
             if (time.time() - self.lastTime) > self.screens[self.index][1]:
31
-                self.index = (self.index + 1) % len(self.screens)
32 31
                 self.lastTime = time.time()
32
+                self.index = (self.index + 1) % len(self.screens)
33 33
                 self.screens[self.index][0].restart()
34 34
 
35 35
 if __name__ == "__main__":
36 36
     from splash import SplashScreen
37
-    #from weather import WeatherScreen
38 37
     from draw import ScrollText
39 38
     from solid import Solid
40 39
     from life import GameOfLife
@@ -53,9 +52,6 @@ if __name__ == "__main__":
53 52
     m.add(SplashScreen(t), 2)
54 53
     m.add(Solid(t, 1.0))
55 54
 
56
-    #m.add(WeatherScreen(t), 4)
57
-    #m.add(Solid(t, 1.0))
58
-
59 55
     m.add(ScrollText(t, "This appears once"))
60 56
     m.add(Solid(t, 1.0))
61 57
 

+ 0
- 73
weather.py 파일 보기

@@ -1,73 +0,0 @@
1
-#!/usr/bin/env python3
2
-
3
-from pyowm.owm import OWM
4
-from pyowm.utils.config import get_default_config
5
-
6
-import time
7
-
8
-api_key = "7de9d39fd4476f811000ceecbbe69376"
9
-
10
-class WeatherScreen:
11
-    def __init__(self, gui, latitude = 47.7174, longitude = 9.3924, language = "de", refresh = 600, width = 32, height = 32):
12
-        self.gui = gui
13
-        self.latitude = latitude
14
-        self.longitude = longitude
15
-        self.language = language
16
-        self.refresh = refresh
17
-        self.width = width
18
-        self.height = height
19
-
20
-        self.lastTime = time.time()
21
-        self.data = ""
22
-
23
-        self.fetchData()
24
-
25
-    def fetchData(self):
26
-        config_dict = get_default_config()
27
-        config_dict['language'] = self.language
28
-        owm = OWM(api_key, config_dict)
29
-        mgr = owm.weather_manager()
30
-
31
-        observation = mgr.weather_at_place("Tuttlingen, DE")
32
-        print(observation.weather.rain)
33
-        print(observation.weather.snow)
34
-        print(observation.weather.wind)
35
-        print(observation.weather.humidity)
36
-        print(observation.weather.pressure)
37
-        print(observation.weather.temperature)
38
-        print(observation.weather.clouds)
39
-        print(observation.weather.status)
40
-        print(observation.weather.detailed_status)
41
-        print(observation.weather.weather_icon_name)
42
-        print(observation.weather.precipitation_probability)
43
-
44
-        #self.data = mgr.one_call(lat=self.latitude, lon=self.longitude)
45
-        #print(self.data.forecast_hourly[0].wind().get("speed", 0))
46
-
47
-    def draw(self):
48
-        if (time.time() - self.lastTime) > self.refresh:
49
-            self.fetchData()
50
-            self.lastTime = time.time()
51
-
52
-        # TODO text location
53
-        # TODO text data
54
-
55
-    def finished(self):
56
-        return True
57
-
58
-    def restart(self):
59
-        pass
60
-
61
-if __name__ == "__main__":
62
-    import platform
63
-    t = None
64
-    if platform.machine() == "armv7l":
65
-        from pi import PiMatrix
66
-        t = PiMatrix()
67
-    else:
68
-        from test import TestGUI
69
-        t = TestGUI()
70
-
71
-    s = WeatherScreen(t)
72
-    s.draw()
73
-    t.debug_loop(s.draw)

Loading…
취소
저장