Thomas Buck 9 місяці тому
джерело
коміт
72ad2d2fe0
10 змінених файлів з 228 додано та 46 видалено
  1. 71
    16
      breakout.py
  2. 8
    4
      camp_pico.py
  3. 37
    19
      camp_small.py
  4. 81
    0
      hardware/frame.scad
  5. BIN
      hardware/frame.stl
  6. 12
    0
      image.py
  7. 4
    2
      pi.py
  8. 11
    2
      snake.py
  9. 1
    1
      test.py
  10. 3
    2
      util.py

+ 71
- 16
breakout.py Переглянути файл

11
 import time
11
 import time
12
 import random
12
 import random
13
 import math
13
 import math
14
+import util
14
 
15
 
15
 class Breakout:
16
 class Breakout:
16
     def __init__(self, g, i, ts = 0.1, to = 60.0):
17
     def __init__(self, g, i, ts = 0.1, to = 60.0):
19
         self.timestep = ts
20
         self.timestep = ts
20
         self.timeout = to
21
         self.timeout = to
21
 
22
 
22
-        self.paddle_width = 9
23
+        self.paddle_width = 43#9
23
 
24
 
24
         self.winText = ScrollText(self.gui, "You Won!", "uushi",
25
         self.winText = ScrollText(self.gui, "You Won!", "uushi",
25
                                   2, 50, (0, 255, 0))
26
                                   2, 50, (0, 255, 0))
28
         self.scoreText = ScrollText(self.gui, "Score:", "uushi",
29
         self.scoreText = ScrollText(self.gui, "Score:", "uushi",
29
                                     2, 50, (255, 255, 255))
30
                                     2, 50, (255, 255, 255))
30
 
31
 
32
+        self.bg_c = (0, 0, 0)
33
+        self.fg_c = (0, 255, 0)
34
+        self.ball_c = (255, 0, 0)
35
+        self.paddle_c = (255, 255, 255)
36
+        self.text_c = (0, 0, 255)
37
+
31
         random.seed()
38
         random.seed()
32
         self.restart()
39
         self.restart()
33
 
40
 
47
         self.score = 0
54
         self.score = 0
48
         self.direction = ""
55
         self.direction = ""
49
 
56
 
50
-        self.data = [[(0, 0, 0) for y in range(self.gui.height)] for x in range(self.gui.width)]
57
+        self.data = [[self.bg_c for y in range(self.gui.height)] for x in range(self.gui.width)]
51
 
58
 
52
         for x in range(self.gui.width - 2):
59
         for x in range(self.gui.width - 2):
53
             for y in range(5):
60
             for y in range(5):
54
-                self.data[x + 1][y] = (0, 255, 0)
61
+                self.data[x + 1][y] = self.fg_c
62
+        self.maxScore = 5 * (self.gui.width - 2)
63
+
64
+        # TODO easy mode
65
+        self.nothing_to_lose = True
66
+
67
+        DrawText = util.getTextDrawer()
68
+        self.text = DrawText(self.gui, self.text_c)
55
 
69
 
56
         self.place()
70
         self.place()
57
 
71
 
95
         self.old_keys = keys.copy()
109
         self.old_keys = keys.copy()
96
 
110
 
97
     def step(self):
111
     def step(self):
98
-        # TODO check for collisions with pieces
99
-
100
         # move ball
112
         # move ball
101
         self.ball[0] += self.ball[2]
113
         self.ball[0] += self.ball[2]
102
         self.ball[1] += self.ball[3]
114
         self.ball[1] += self.ball[3]
104
         # check for collision with left wall
116
         # check for collision with left wall
105
         if self.ball[0] <= 0:
117
         if self.ball[0] <= 0:
106
             self.ball[2] = -self.ball[2]
118
             self.ball[2] = -self.ball[2]
119
+            self.ball[0] = 0
107
 
120
 
108
         # check for collision with right wall
121
         # check for collision with right wall
109
         if self.ball[0] >= self.gui.width - 1:
122
         if self.ball[0] >= self.gui.width - 1:
110
             self.ball[2] = -self.ball[2]
123
             self.ball[2] = -self.ball[2]
124
+            self.ball[0] = self.gui.width - 1
125
+
126
+        # check for collisions with pieces
127
+        if self.data[int(self.ball[0])][int(self.ball[1])] != self.bg_c:
128
+            self.data[int(self.ball[0])][int(self.ball[1])] = self.bg_c
129
+            self.score += 1
130
+
131
+            # just invert Y travel direction
132
+            # TODO inaccurate collision behaviour in "corners"
133
+            self.ball[3] = -self.ball[3]
111
 
134
 
112
         # check for collision with ceiling
135
         # check for collision with ceiling
113
         if self.ball[1] <= 0:
136
         if self.ball[1] <= 0:
115
 
138
 
116
         # check for collision with paddle
139
         # check for collision with paddle
117
         if (self.ball[1] == self.gui.height - 2) and (self.ball[0] >= (self.player - int(self.paddle_width / 2))) and (self.ball[0] <= (self.player + int(self.paddle_width / 2))):
140
         if (self.ball[1] == self.gui.height - 2) and (self.ball[0] >= (self.player - int(self.paddle_width / 2))) and (self.ball[0] <= (self.player + int(self.paddle_width / 2))):
118
-            # TODO angle
119
-            self.ball[3] = -self.ball[3]
141
+            # TODO angle for bounce from paddle
142
+            #self.ball[3] = -self.ball[3]
143
+            d = self.ball[0] - (self.player - (self.paddle_width / 2))
144
+            angle = (d / self.paddle_width - 0.5) / 2 * 3.14159
145
+            print(math.degrees(angle))
146
+            self.ball[2] = math.cos(angle) * math.sqrt(2)
147
+            self.ball[3] = math.sin(angle) * math.sqrt(2)
120
 
148
 
121
         # check for collision with floor
149
         # check for collision with floor
122
         if self.ball[1] >= self.gui.height - 1:
150
         if self.ball[1] >= self.gui.height - 1:
123
-            self.place()
124
-            self.lives -= 1
151
+            if self.nothing_to_lose:
152
+                # TODO should this bounce with an angle?
153
+                self.ball[3] = -self.ball[3]
154
+            else:
155
+                self.place()
156
+                self.lives -= 1
125
 
157
 
126
     def finishedEndScreen(self):
158
     def finishedEndScreen(self):
127
-        if self.score >= self.gui.width * self.gui.height:
159
+        if self.score >= self.maxScore:
128
             return self.winText.finished()
160
             return self.winText.finished()
129
         else:
161
         else:
130
             return self.loseText.finished()
162
             return self.loseText.finished()
131
 
163
 
132
     def drawEndScreen(self):
164
     def drawEndScreen(self):
133
-        if self.score >= self.gui.width * self.gui.height:
165
+        if self.score >= self.maxScore:
134
             self.winText.draw()
166
             self.winText.draw()
135
         else:
167
         else:
136
             self.loseText.draw()
168
             self.loseText.draw()
139
         self.scoreText.draw()
171
         self.scoreText.draw()
140
 
172
 
141
     def draw(self):
173
     def draw(self):
174
+        # handle / generate player inputs
142
         if self.input != None:
175
         if self.input != None:
143
             self.buttons()
176
             self.buttons()
144
         else:
177
         else:
145
             # TODO "AI"
178
             # TODO "AI"
146
             pass
179
             pass
147
 
180
 
148
-        if self.lives < 0:
181
+        # only draw end-cards when game is over
182
+        if (self.lives < 0) or (self.score >= self.maxScore):
149
             if self.finishedEndScreen():
183
             if self.finishedEndScreen():
150
                 self.drawScoreScreen()
184
                 self.drawScoreScreen()
151
             else:
185
             else:
153
                 self.scoreText.restart()
187
                 self.scoreText.restart()
154
             return
188
             return
155
 
189
 
190
+        # move paddle according to player input
156
         if self.direction == "l":
191
         if self.direction == "l":
157
             self.player = max(self.player - 1, 0)
192
             self.player = max(self.player - 1, 0)
158
         elif self.direction == "r":
193
         elif self.direction == "r":
159
             self.player = min(self.player + 1, self.gui.width - 1)
194
             self.player = min(self.player + 1, self.gui.width - 1)
160
         self.direction = ""
195
         self.direction = ""
161
 
196
 
197
+        # run next iteration
162
         now = time.time()
198
         now = time.time()
163
         if (now - self.last) >= self.timestep:
199
         if (now - self.last) >= self.timestep:
164
             self.last = now
200
             self.last = now
165
             self.step()
201
             self.step()
166
 
202
 
167
-            if self.lives < 0:
203
+            # end game when all lives lost or when won
204
+            if (self.lives < 0) or (self.score >= self.maxScore):
168
                 self.scoreText.setText("Score: " + str(self.score), "uushi")
205
                 self.scoreText.setText("Score: " + str(self.score), "uushi")
169
                 self.winText.restart()
206
                 self.winText.restart()
170
                 self.loseText.restart()
207
                 self.loseText.restart()
171
                 self.scoreText.restart()
208
                 self.scoreText.restart()
172
 
209
 
210
+        # draw targets on playing area
173
         for x in range(0, self.gui.width):
211
         for x in range(0, self.gui.width):
174
             for y in range(0, self.gui.height):
212
             for y in range(0, self.gui.height):
175
                 self.gui.set_pixel(x, y, self.data[x][y])
213
                 self.gui.set_pixel(x, y, self.data[x][y])
176
 
214
 
215
+        # draw score
216
+        self.text.setText(str(self.score), "tom-thumb")
217
+        self.text.draw(-1, self.gui.height / 2 - 2)
218
+
219
+        # draw lives
220
+        self.text.setText(str(self.lives), "tom-thumb")
221
+        self.text.draw(-self.gui.width + 4, self.gui.height / 2 - 2)
222
+
223
+        # draw paddle
177
         for x in range(0, self.paddle_width):
224
         for x in range(0, self.paddle_width):
178
-            self.gui.set_pixel(x + self.player - int(self.paddle_width / 2), self.gui.height - 1, (255, 255, 255))
225
+            self.gui.set_pixel(x + self.player - int(self.paddle_width / 2), self.gui.height - 1, self.paddle_c)
179
 
226
 
180
-        self.gui.set_pixel(self.ball[0], self.ball[1], (255, 0, 0))
227
+        # draw ball
228
+        self.gui.set_pixel(int(self.ball[0]), int(self.ball[1]), self.ball_c)
181
 
229
 
182
 if __name__ == "__main__":
230
 if __name__ == "__main__":
183
-    import util
184
     # Need to import InputWrapper before initializing RGB Matrix on Pi
231
     # Need to import InputWrapper before initializing RGB Matrix on Pi
185
     i = util.getInput()
232
     i = util.getInput()
186
     t = util.getTarget(i)
233
     t = util.getTarget(i)
187
 
234
 
188
     d = Breakout(t, i)
235
     d = Breakout(t, i)
236
+
237
+    # example color modifications
238
+    d.fg_c = (0, 150, 0)
239
+    d.ball_c = (150, 0, 0)
240
+    d.paddle_c = (150, 150, 150)
241
+    d.text_c = (0, 0, 150)
242
+    d.restart() # re-gen with new colors
243
+
189
     util.loop(t, d.draw)
244
     util.loop(t, d.draw)

+ 8
- 4
camp_pico.py Переглянути файл

26
 #url = "http://ubabot.frubar.net"
26
 #url = "http://ubabot.frubar.net"
27
 url = "http://www.xythobuz.de"
27
 url = "http://www.xythobuz.de"
28
 
28
 
29
+scroll_speed = 10
30
+
29
 import util
31
 import util
30
 i = util.getInput()
32
 i = util.getInput()
31
 t = util.getTarget(i)
33
 t = util.getTarget(i)
39
 
41
 
40
 # UbaBot is online
42
 # UbaBot is online
41
 success = Manager(t)
43
 success = Manager(t)
42
-success.add(ScrollText(t, "Visit UbaBot Cocktail machine at FruBar village for drinks!", "bitmap8", 1, 10, camp_green))
44
+success.add(ScrollText(t, "Visit UbaBot Cocktail machine at FruBar village for drinks!", "bitmap8", 1, scroll_speed, camp_green))
43
 success.add(Solid(t, 1.0))
45
 success.add(Solid(t, 1.0))
44
 success.add(QRScreen(t, qr_data, 30.0, "Drinks", "bitmap6", camp_pink, (0, 0, 0)))
46
 success.add(QRScreen(t, qr_data, 30.0, "Drinks", "bitmap6", camp_pink, (0, 0, 0)))
45
 success.add(Solid(t, 1.0))
47
 success.add(Solid(t, 1.0))
46
 
48
 
47
 # UbaBot is offline
49
 # UbaBot is offline
48
 fail = Manager(t)
50
 fail = Manager(t)
49
-fail.add(ScrollText(t, "#CCCAMP23", "bitmap8", 1, 10, camp_green))
51
+fail.add(ScrollText(t, "#CCCAMP23", "bitmap8", 1, scroll_speed, camp_green))
50
 fail.add(Solid(t, 1.0))
52
 fail.add(Solid(t, 1.0))
51
-fail.add(ScrollText(t, "The UbaBot Cocktail machine is closed. Please come back later!", "bitmap8", 1, 10, camp_green))
53
+fail.add(ScrollText(t, "The UbaBot Cocktail machine is closed. Please come back later!", "bitmap8", 1, scroll_speed, camp_green))
52
 fail.add(Solid(t, 1.0))
54
 fail.add(Solid(t, 1.0))
53
 fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
55
 fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
54
 fail.add(Solid(t, 1.0))
56
 fail.add(Solid(t, 1.0))
55
-fail.add(ScrollText(t, "Your advertisement could appear here. Open a Pull Request on git.xythobuz.de/thomas/rgb-matrix-visualizer or send an e-mail to thomas@xythobuz.de", "bitmap8", 1, 10, camp_green))
57
+fail.add(ScrollText(t, "Your advertisement could appear here. Open a Pull Request on git.xythobuz.de/thomas/rgb-matrix-visualizer or send an e-mail to thomas@xythobuz.de", "bitmap8", 1, scroll_speed, camp_green))
56
 fail.add(Solid(t, 1.0))
58
 fail.add(Solid(t, 1.0))
57
 
59
 
58
 # UbaBot status checker
60
 # UbaBot status checker
66
 m.add(Solid(t, 1.0))
68
 m.add(Solid(t, 1.0))
67
 m.add(d) # HTTP Check, either "success" or "fail"
69
 m.add(d) # HTTP Check, either "success" or "fail"
68
 m.add(Solid(t, 1.0))
70
 m.add(Solid(t, 1.0))
71
+m.add(ScrollText(t, "Need to print something? FruBar village has a 3D printer. Come by!", "bitmap8", 1, scroll_speed, camp_pink))
72
+m.add(Solid(t, 1.0))
69
 m.add(PicoBatt(t, 5.0, 5.0))
73
 m.add(PicoBatt(t, 5.0, 5.0))
70
 m.add(Solid(t, 1.0))
74
 m.add(Solid(t, 1.0))
71
 
75
 

+ 37
- 19
camp_small.py Переглянути файл

22
 from manager import Manager
22
 from manager import Manager
23
 import util
23
 import util
24
 
24
 
25
-#url = "http://ubabot.frubar.net"
26
-url = "http://www.xythobuz.de"
25
+url_uba = "http://ubabot.frubar.net"
26
+url_printer = "http://i3-am8.fritz.box"
27
 
27
 
28
 scroll_speed = 50
28
 scroll_speed = 50
29
 
29
 
39
 t.loop_end()
39
 t.loop_end()
40
 
40
 
41
 # UbaBot is online
41
 # UbaBot is online
42
-success = Manager(t)
43
-success.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0, (0, 0, 0)))
44
-success.add(Solid(t, 1.0))
45
-success.add(ScrollText(t, "Visit the UbaBot Cocktail machine at FruBar village for drinks!", "lemon", 2, scroll_speed, camp_green))
46
-success.add(Solid(t, 1.0))
47
-success.add(QRScreen(t, url, 30.0, "Drinks:", "tom-thumb", camp_pink, (0, 0, 0)))
48
-success.add(Solid(t, 1.0))
42
+success_uba = Manager(t)
43
+success_uba.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0, (0, 0, 0)))
44
+success_uba.add(Solid(t, 1.0))
45
+success_uba.add(ScrollText(t, "Visit the UbaBot Cocktail machine at FruBar village for drinks!", "lemon", 2, scroll_speed, camp_green))
46
+success_uba.add(Solid(t, 1.0))
47
+success_uba.add(QRScreen(t, url_uba, 30.0, "Drinks:", "tom-thumb", camp_pink, (0, 0, 0)))
48
+success_uba.add(Solid(t, 1.0))
49
 
49
 
50
 # UbaBot is offline
50
 # UbaBot is offline
51
-fail = Manager(t)
52
-fail.add(ImageScreen(t, "attention.gif", 0.2, 2, 20.0, (0, 0, 0)))
53
-fail.add(Solid(t, 1.0))
54
-fail.add(ScrollText(t, "The UbaBot Cocktail machine is currently closed. Please come back later for more drinks!", "lemon", 2, scroll_speed, camp_pink))
55
-fail.add(Solid(t, 1.0))
56
-fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
57
-fail.add(Solid(t, 1.0))
51
+fail_uba = Manager(t)
52
+fail_uba.add(ImageScreen(t, "attention.gif", 0.2, 2, 20.0, (0, 0, 0)))
53
+fail_uba.add(Solid(t, 1.0))
54
+fail_uba.add(ScrollText(t, "The UbaBot Cocktail machine is currently closed. Please come back later for more drinks!", "lemon", 2, scroll_speed, camp_pink))
55
+fail_uba.add(Solid(t, 1.0))
56
+fail_uba.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
57
+fail_uba.add(Solid(t, 1.0))
58
 
58
 
59
 # UbaBot status checker
59
 # UbaBot status checker
60
-d = CheckHTTP(url)
61
-d.success(success)
62
-d.fail(fail)
60
+d = CheckHTTP(url_uba)
61
+d.success(success_uba)
62
+d.fail(fail_uba)
63
+
64
+# 3D printer is online
65
+success_printer = Manager(t)
66
+success_printer.add(ScrollText(t, "Need to print something? FruBar village has a 3D printer. Come by!", "iv18x16u", 1, scroll_speed, camp_pink))
67
+success_printer.add(Solid(t, 1.0))
68
+
69
+# 3D printer is offline
70
+fail_printer = Manager(t)
71
+fail_printer.add(Solid(t, 1.0))
72
+fail_printer.add(Solid(t, 1.0))
73
+
74
+# Printer status checker
75
+d2 = CheckHTTP(url_printer)
76
+d2.success(success_printer)
77
+d2.fail(fail_printer)
63
 
78
 
64
 # Main "Menu"
79
 # Main "Menu"
65
 m = Manager(t, i)
80
 m = Manager(t, i)
67
 m.add(Solid(t, 1.0))
82
 m.add(Solid(t, 1.0))
68
 m.add(ImageScreen(t, "Favicon.png", 0, 1, 10.0))
83
 m.add(ImageScreen(t, "Favicon.png", 0, 1, 10.0))
69
 m.add(Solid(t, 1.0))
84
 m.add(Solid(t, 1.0))
85
+m.add(ScrollText(t, "Grab a cold draft beer at FruBar village!", "iv18x16u", 1, scroll_speed, camp_green))
70
 m.add(d) # HTTP Check, either "success" or "fail"
86
 m.add(d) # HTTP Check, either "success" or "fail"
71
 m.add(Solid(t, 1.0))
87
 m.add(Solid(t, 1.0))
88
+m.add(d2) # HTTP Check, either "success" or "fail"
89
+m.add(Solid(t, 1.0))
72
 m.add(Snake(t, i, camp_pink, camp_green))
90
 m.add(Snake(t, i, camp_pink, camp_green))
73
 m.add(Solid(t, 1.0))
91
 m.add(Solid(t, 1.0))
74
 m.add(ScrollText(t, "Your advertisement could appear here. Open a Pull Request on git.xythobuz.de/thomas/rgb-matrix-visualizer or send an e-mail to thomas@xythobuz.de", "iv18x16u", 2, scroll_speed, camp_green))
92
 m.add(ScrollText(t, "Your advertisement could appear here. Open a Pull Request on git.xythobuz.de/thomas/rgb-matrix-visualizer or send an e-mail to thomas@xythobuz.de", "iv18x16u", 2, scroll_speed, camp_green))

+ 81
- 0
hardware/frame.scad Переглянути файл

1
+dia = 14.5;
2
+rod_l = 1200;
3
+
4
+wall = 4;
5
+clamp_d = dia + wall * 2;
6
+clamp_h = 30;
7
+screw = 4.5;
8
+
9
+l = rod_l + 2 * dia;
10
+
11
+plane_off = 100;
12
+plane_l = rod_l - plane_off;
13
+
14
+echo("rod", rod_l);
15
+echo("plane", plane_l);
16
+echo("outer", l);
17
+
18
+$fn = $preview ? 42 : 100;
19
+
20
+module rods() {
21
+    // left/right
22
+    for (x = [0, l])
23
+    translate([x, 0, 0])
24
+    cylinder(d = dia, h = rod_l);
25
+    
26
+    // top/bottom
27
+    for (z = [0, l])
28
+    translate([dia, 0, z - dia])
29
+    rotate([0, 90, 0])
30
+    cylinder(d = dia, h = rod_l);
31
+    
32
+    // plane
33
+    translate([(l - plane_l) / 2, 0, -dia + (l - plane_l) / 2 - 1 * plane_off])
34
+    cube([plane_l, 1, plane_l + 2 * plane_off]);
35
+    translate([(l - plane_l) / 2 - 1 * plane_off, 0, -dia + (l - plane_l) / 2])
36
+    cube([plane_l + 2 * plane_off, 1, plane_l]);
37
+}
38
+
39
+module clamp() {
40
+    difference() {
41
+        union() {
42
+            hull()
43
+            for (r = [0, 90])
44
+            rotate([0, r, 0])
45
+            translate([0, 0, dia])
46
+            cylinder(d = clamp_d, h = clamp_h / 2);
47
+            
48
+            for (r = [0, 90])
49
+            rotate([0, r, 0])
50
+            translate([0, 0, dia])
51
+            cylinder(d = clamp_d, h = clamp_h);
52
+        }
53
+        
54
+        for (r = [0, 90])
55
+        rotate([0, r, 0])
56
+        translate([0, 0, dia])
57
+        translate([0, 0, -20])
58
+        cylinder(d = dia, h = clamp_h + 30);
59
+        
60
+        for (i = [0, 1])
61
+        translate([i ? clamp_h * 3 / 4 + dia : 0, clamp_d / 2 + 1, i ? 0 : clamp_h * 3 / 4 + dia])
62
+        rotate([90, 0, 0])
63
+        cylinder(d = screw, h = clamp_d + 2);
64
+    }
65
+}
66
+
67
+module frame() {
68
+    %translate([-l / 2, 0, dia - l / 2])
69
+    rods();
70
+    
71
+    for (r = [0 : 90 : 360])
72
+    rotate([0, r, 0])
73
+    translate([-l/ 2, 0, -l / 2])
74
+    clamp();
75
+}
76
+
77
+if ($preview)
78
+    translate([l / 2, 0, l / 2])
79
+    frame();
80
+else
81
+    clamp();

BIN
hardware/frame.stl Переглянути файл


+ 12
- 0
image.py Переглянути файл

65
             self.image.is_animated = False
65
             self.image.is_animated = False
66
             self.image.n_frames = 1
66
             self.image.n_frames = 1
67
 
67
 
68
+        # enlarge small images
69
+        if not self.image.is_animated and ((self.image.width * 2) <= self.gui.width) and ((self.image.height * 2) <= self.gui.height):
70
+            self.image = self.image.crop(self.image.getbbox())
71
+            self.image = self.image.resize((self.image.width * 2, self.image.height * 2),
72
+                                           Image.Resampling.NEAREST)
73
+            self.image.is_animated = False
74
+            self.image.n_frames = 1
75
+
76
+        # TODO cropping and scaling not working for GIF animations
77
+
68
         print(p, self.image.width, self.image.height, self.image.is_animated, self.image.n_frames)
78
         print(p, self.image.width, self.image.height, self.image.is_animated, self.image.n_frames)
69
 
79
 
70
         self.xOff = int((self.gui.width - self.image.width) / 2)
80
         self.xOff = int((self.gui.width - self.image.width) / 2)
142
 
152
 
143
         if filename != "Favicon.png":
153
         if filename != "Favicon.png":
144
             continue
154
             continue
155
+        if (t.width != 32) or (t.height != 32):
156
+            continue
145
 
157
 
146
         try:
158
         try:
147
             # dump generated image to console, for embedding in Pico script
159
             # dump generated image to console, for embedding in Pico script

+ 4
- 2
pi.py Переглянути файл

32
 from PIL import Image
32
 from PIL import Image
33
 
33
 
34
 class PiMatrix:
34
 class PiMatrix:
35
-    def __init__(self, w = 32 * 2, h = 32, panelW = 32, panelH = 32):
35
+    def __init__(self, w = 32 * 4, h = 32, panelW = 32, panelH = 32):
36
         self.width = w # x-axis
36
         self.width = w # x-axis
37
         self.height = h # y-axis
37
         self.height = h # y-axis
38
 
38
 
86
         self.image.putpixel((int(x), int(y)), color)
86
         self.image.putpixel((int(x), int(y)), color)
87
 
87
 
88
 if __name__ == "__main__":
88
 if __name__ == "__main__":
89
-    t = PiMatrix(32, 32)
89
+    import util
90
+
91
+    t = PiMatrix()
90
     util.loop(t, lambda: t.set_pixel(15, 15, (255, 255, 255)))
92
     util.loop(t, lambda: t.set_pixel(15, 15, (255, 255, 255)))

+ 11
- 2
snake.py Переглянути файл

10
 from scroll import ScrollText
10
 from scroll import ScrollText
11
 import time
11
 import time
12
 import random
12
 import random
13
+import util
13
 
14
 
14
 class Snake:
15
 class Snake:
15
     def __init__(self, g, i, sc = (0, 255, 0), d = (0, 0, 255), bg = (0, 0, 0), ts = 0.3, su = 0.75, to = 60.0):
16
     def __init__(self, g, i, sc = (0, 255, 0), d = (0, 0, 255), bg = (0, 0, 0), ts = 0.3, su = 0.75, to = 60.0):
27
         self.scoreText = ScrollText(self.gui, "Score:", "uushi",
28
         self.scoreText = ScrollText(self.gui, "Score:", "uushi",
28
                                     2, 50, sc)
29
                                     2, 50, sc)
29
 
30
 
31
+        self.text_c = (0, 0, 255)
32
+
30
         random.seed()
33
         random.seed()
31
         self.restart()
34
         self.restart()
32
 
35
 
41
         self.player = [ (int(self.gui.width / 2), int(self.gui.height / 2)) ]
44
         self.player = [ (int(self.gui.width / 2), int(self.gui.height / 2)) ]
42
         self.data[self.player[0][0]][self.player[0][1]] = 1
45
         self.data[self.player[0][0]][self.player[0][1]] = 1
43
 
46
 
47
+        DrawText = util.getTextDrawer()
48
+        self.text = DrawText(self.gui, self.text_c)
49
+
44
         self.old_keys = {
50
         self.old_keys = {
45
             "left": False,
51
             "left": False,
46
             "right": False,
52
             "right": False,
72
 
78
 
73
     def placeDot(self):
79
     def placeDot(self):
74
         d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
80
         d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
75
-        while self.data[d[0]][d[1]] != 0:
81
+        while self.data[d[0]][d[1]] != 0: # TODO don't place dots below score text
76
             d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
82
             d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
77
         self.data[d[0]][d[1]] = 2
83
         self.data[d[0]][d[1]] = 2
78
 
84
 
177
             for y in range(0, self.gui.height):
183
             for y in range(0, self.gui.height):
178
                 self.gui.set_pixel(x, y, self.colors[self.data[x][y]])
184
                 self.gui.set_pixel(x, y, self.colors[self.data[x][y]])
179
 
185
 
186
+        # draw score
187
+        self.text.setText(str(self.score), "tom-thumb")
188
+        self.text.draw(-1, self.gui.height / 2 - 2)
189
+
180
 if __name__ == "__main__":
190
 if __name__ == "__main__":
181
-    import util
182
     # Need to import InputWrapper before initializing RGB Matrix on Pi
191
     # Need to import InputWrapper before initializing RGB Matrix on Pi
183
     i = util.getInput()
192
     i = util.getInput()
184
     t = util.getTarget(i)
193
     t = util.getTarget(i)

+ 1
- 1
test.py Переглянути файл

13
 import pygame
13
 import pygame
14
 
14
 
15
 class TestGUI:
15
 class TestGUI:
16
-    def __init__(self, width = 32 * 1, height = 32, multiplier = 16):
16
+    def __init__(self, width = 32 * 2, height = 32 * 2, multiplier = 16):
17
         self.width = width
17
         self.width = width
18
         self.height = height
18
         self.height = height
19
         self.multiplier = multiplier
19
         self.multiplier = multiplier

+ 3
- 2
util.py Переглянути файл

44
         # TODO hard-coded adjustments
44
         # TODO hard-coded adjustments
45
         from mapper import MapperReduceBrightness, MapperColorAdjust, MapperStripToRect
45
         from mapper import MapperReduceBrightness, MapperColorAdjust, MapperStripToRect
46
         bright = MapperReduceBrightness(pi, i)
46
         bright = MapperReduceBrightness(pi, i)
47
-        col = MapperColorAdjust(bright)
47
+        #col = MapperColorAdjust(bright)
48
+        #target = col
48
         #target = MapperStripToRect(col)
49
         #target = MapperStripToRect(col)
49
-        target = col
50
+        target = MapperStripToRect(bright)
50
 
51
 
51
         if targetPlatform == None:
52
         if targetPlatform == None:
52
             # only print once
53
             # only print once

Завантаження…
Відмінити
Зберегти