-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrix.py
68 lines (52 loc) · 1.4 KB
/
matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
from FakeHat import FakeHat
import unittest
import sys
class Matrix:
hat = None
def __init__(self, hat=None):
if hat:
self.hat = hat
else:
hat = FakeHat()
self.hat = hat
self.AREA = hat.AREA
def show(self, matrix_colors):
w = self.hat.WIDTH
h = self.hat.HEIGHT
area = self.AREA
count = len(matrix_colors)
for pos in range(self.AREA):
x = pos % w
y = pos // h
if pos < count:
color = matrix_colors[pos]
self.hat.set_pixel(x,y,color[0],color[1],color[2])
else:
self.hat.set_pixel(x,y,0,0,0)
self.hat.show()
self.dump()
def brightness(self,b):
self.hat.brightness(b)
def dump(self):
self.hat.dump()
class TestMatrix(unittest.TestCase):
def test_setting_some_pixels(self):
matrix = Matrix()
self.assertNotEqual(None,matrix.hat)
matrix.show([(1,2,3),(4,5,6)])
self.assertEqual((4,5,6), matrix.hat.get_pixel(1,0))
self.assertEqual((0,0,0), matrix.hat.get_pixel(0,1))
self.assertEqual((0,0,0), matrix.hat.get_pixel(1,1))
def test_overflow_is_ignored(self):
matrix = Matrix()
col = (1,2,3)
colors = [col] * matrix.AREA
colors.append((42,42,42))
matrix.show(colors)
self.assertEqual(col, matrix.hat.get_pixel(0,0))
self.assertEqual(col, matrix.hat.get_pixel(0,1))
self.assertEqual(col, matrix.hat.get_pixel(1,1))
self.assertEqual(col, matrix.hat.get_pixel(1,0))
if __name__ == "__main__":
unittest.main()