30
30
__version__ = "0.0.0-auto.0"
31
31
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
32
32
33
+
33
34
class Matrix8x8 (HT16K33 ):
34
35
"""A single matrix."""
36
+
35
37
_columns = 8
36
38
_rows = 8
37
39
@@ -52,7 +54,7 @@ def __setitem__(self, key, value):
52
54
x , y = key
53
55
self .pixel (x , y , value )
54
56
55
- #pylint: disable=too-many-branches
57
+ # pylint: disable=too-many-branches
56
58
def shift (self , x , y , rotate = False ):
57
59
"""
58
60
Shift pixels by x and y
@@ -61,28 +63,28 @@ def shift(self, x, y, rotate=False):
61
63
"""
62
64
auto_write = self .auto_write
63
65
self ._auto_write = False
64
- if x > 0 : # Shift Right
66
+ if x > 0 : # Shift Right
65
67
for _ in range (x ):
66
68
for row in range (0 , self .rows ):
67
69
last_pixel = self [self .columns - 1 , row ] if rotate else 0
68
70
for col in range (self .columns - 1 , 0 , - 1 ):
69
71
self [col , row ] = self [col - 1 , row ]
70
72
self [0 , row ] = last_pixel
71
- elif x < 0 : # Shift Left
73
+ elif x < 0 : # Shift Left
72
74
for _ in range (- x ):
73
75
for row in range (0 , self .rows ):
74
76
last_pixel = self [0 , row ] if rotate else 0
75
77
for col in range (0 , self .columns - 1 ):
76
78
self [col , row ] = self [col + 1 , row ]
77
79
self [self .columns - 1 , row ] = last_pixel
78
- if y > 0 : # Shift Up
80
+ if y > 0 : # Shift Up
79
81
for _ in range (y ):
80
82
for col in range (0 , self .columns ):
81
83
last_pixel = self [col , self .rows - 1 ] if rotate else 0
82
84
for row in range (self .rows - 1 , 0 , - 1 ):
83
85
self [col , row ] = self [col , row - 1 ]
84
86
self [col , 0 ] = last_pixel
85
- elif y < 0 : # Shift Down
87
+ elif y < 0 : # Shift Down
86
88
for _ in range (- y ):
87
89
for col in range (0 , self .columns ):
88
90
last_pixel = self [col , 0 ] if rotate else 0
@@ -92,7 +94,8 @@ def shift(self, x, y, rotate=False):
92
94
self ._auto_write = auto_write
93
95
if auto_write :
94
96
self .show ()
95
- #pylint: enable=too-many-branches
97
+
98
+ # pylint: enable=too-many-branches
96
99
97
100
def shift_right (self , rotate = False ):
98
101
"""
@@ -131,12 +134,15 @@ def image(self, img):
131
134
be in 1 bit mode and a size equal to the display size."""
132
135
imwidth , imheight = img .size
133
136
if imwidth != self .columns or imheight != self .rows :
134
- raise ValueError ('Image must be same dimensions as display ({0}x{1}).' \
135
- .format (self .columns , self .rows ))
137
+ raise ValueError (
138
+ "Image must be same dimensions as display ({0}x{1})." .format (
139
+ self .columns , self .rows
140
+ )
141
+ )
136
142
# Grab all the pixels from the image, faster than getpixel.
137
- pixels = img .convert ('1' ).load ()
143
+ pixels = img .convert ("1" ).load ()
138
144
# Iterate through the pixels
139
- for x in range (self .columns ): # yes this double loop is slow,
145
+ for x in range (self .columns ): # yes this double loop is slow,
140
146
for y in range (self .rows ): # but these displays are small!
141
147
self .pixel (x , y , pixels [(x , y )])
142
148
if self ._auto_write :
@@ -152,8 +158,10 @@ def rows(self):
152
158
"""Read-only property for number of rows"""
153
159
return self ._rows
154
160
161
+
155
162
class Matrix16x8 (Matrix8x8 ):
156
163
"""The matrix wing."""
164
+
157
165
_columns = 16
158
166
159
167
def pixel (self , x , y , color = None ):
@@ -165,10 +173,12 @@ def pixel(self, x, y, color=None):
165
173
if x >= 8 :
166
174
x -= 8
167
175
y += 8
168
- return super ()._pixel (y , x , color )
176
+ return super ()._pixel (y , x , color ) # pylint: disable=arguments-out-of-order
177
+
169
178
170
179
class MatrixBackpack16x8 (Matrix16x8 ):
171
180
"""A double matrix backpack."""
181
+
172
182
def pixel (self , x , y , color = None ):
173
183
"""Get or set the color of a given pixel."""
174
184
if not 0 <= x <= 15 :
@@ -177,6 +187,7 @@ def pixel(self, x, y, color=None):
177
187
return None
178
188
return super ()._pixel (x , y , color )
179
189
190
+
180
191
class Matrix8x8x2 (Matrix8x8 ):
181
192
"""A bi-color matrix."""
182
193
@@ -200,8 +211,8 @@ def pixel(self, x, y, color=None):
200
211
201
212
def fill (self , color ):
202
213
"""Fill the whole display with the given color."""
203
- fill1 = 0xff if color & 0x01 else 0x00
204
- fill2 = 0xff if color & 0x02 else 0x00
214
+ fill1 = 0xFF if color & 0x01 else 0x00
215
+ fill2 = 0xFF if color & 0x02 else 0x00
205
216
for i in range (8 ):
206
217
self ._set_buffer (i * 2 , fill1 )
207
218
self ._set_buffer (i * 2 + 1 , fill2 )
@@ -213,12 +224,15 @@ def image(self, img):
213
224
be a size equal to the display size."""
214
225
imwidth , imheight = img .size
215
226
if imwidth != self .columns or imheight != self .rows :
216
- raise ValueError ('Image must be same dimensions as display ({0}x{1}).' \
217
- .format (self .columns , self .rows ))
227
+ raise ValueError (
228
+ "Image must be same dimensions as display ({0}x{1})." .format (
229
+ self .columns , self .rows
230
+ )
231
+ )
218
232
# Grab all the pixels from the image, faster than getpixel.
219
- pixels = img .convert (' RGB' ).load ()
233
+ pixels = img .convert (" RGB" ).load ()
220
234
# Iterate through the pixels
221
- for x in range (self .columns ): # yes this double loop is slow,
235
+ for x in range (self .columns ): # yes this double loop is slow,
222
236
for y in range (self .rows ): # but these displays are small!
223
237
if pixels [(x , y )] == (255 , 0 , 0 ):
224
238
self .pixel (x , y , self .LED_RED )
0 commit comments