Browse Source

gol faster and random colors. remove broken weather tests.

Thomas Buck 1 year ago
parent
commit
f8d821d9d2
4 changed files with 18 additions and 85 deletions
  1. 1
    2
      draw.py
  2. 15
    4
      life.py
  3. 2
    6
      manager.py
  4. 0
    73
      weather.py

+ 1
- 2
draw.py View File

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

+ 15
- 4
life.py View File

4
 import random
4
 import random
5
 
5
 
6
 class GameOfLife:
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
         self.gui = g
8
         self.gui = g
9
         self.interval = 1.0 / f
9
         self.interval = 1.0 / f
10
-        self.colorFG = c1
11
-        self.colorBG = c2
10
+        self.setColors(c1, c2)
12
         self.timeout = t
11
         self.timeout = t
13
         random.seed()
12
         random.seed()
14
         self.restart()
13
         self.restart()
19
         self.last = time.time()
18
         self.last = time.time()
20
         self.done = False
19
         self.done = False
21
 
20
 
21
+    def setColors(self, c1, c2):
22
+        self.colorFG = c1
23
+        self.colorBG = c2
24
+
22
     def init(self):
25
     def init(self):
23
         data = []
26
         data = []
24
         for x in range(0, self.gui.width):
27
         for x in range(0, self.gui.width):
80
 
83
 
81
     def draw(self):
84
     def draw(self):
82
         if (time.time() - self.last) > self.interval:
85
         if (time.time() - self.last) > self.interval:
83
-            self.step()
84
             self.last = time.time()
86
             self.last = time.time()
87
+            self.step()
85
 
88
 
86
         for x in range(0, self.gui.width):
89
         for x in range(0, self.gui.width):
87
             for y in range(0, self.gui.height):
90
             for y in range(0, self.gui.height):
102
 
105
 
103
     g = GameOfLife(t)
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
     def helper():
115
     def helper():
106
         if g.finished():
116
         if g.finished():
107
             g.restart()
117
             g.restart()
118
+            helperRestart()
108
         g.draw()
119
         g.draw()
109
 
120
 
110
     t.debug_loop(helper)
121
     t.debug_loop(helper)

+ 2
- 6
manager.py View File

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

+ 0
- 73
weather.py View File

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…
Cancel
Save