33
33
34
34
class Matrix8x8 (HT16K33 ):
35
35
"""A single matrix."""
36
+ columns = 8
37
+ rows = 8
38
+
36
39
def pixel (self , x , y , color = None ):
37
40
"""Get or set the color of a given pixel."""
38
41
if not 0 <= x <= 7 :
@@ -50,8 +53,67 @@ def __setitem__(self, key, value):
50
53
x , y = key
51
54
self .pixel (x , y , value )
52
55
56
+ def shift_right (self , rotate = False ):
57
+ """
58
+ Shift all pixels right
59
+
60
+ :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
61
+ """
62
+ for y in range (0 , self .rows ):
63
+ last_pixel = self [self .columns - 1 , y ] if rotate else 0
64
+ for x in range (self .columns - 1 , 0 , - 1 ):
65
+ self [x , y ] = self [x - 1 , y ]
66
+ self [0 , y ] = last_pixel
67
+ if self ._auto_write :
68
+ self .show ()
69
+
70
+ def shift_left (self , rotate = False ):
71
+ """
72
+ Shift all pixels left
73
+
74
+ :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
75
+ """
76
+ for y in range (0 , self .rows ):
77
+ last_pixel = self [0 , y ] if rotate else 0
78
+ for x in range (0 , self .columns - 1 ):
79
+ self [x , y ] = self [x + 1 , y ]
80
+ self [self .columns - 1 , y ] = last_pixel
81
+ if self ._auto_write :
82
+ self .show ()
83
+
84
+ def shift_up (self , rotate = False ):
85
+ """
86
+ Shift all pixels up
87
+
88
+ :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
89
+ """
90
+ for x in range (0 , self .columns ):
91
+ last_pixel = self [x , self .rows - 1 ] if rotate else 0
92
+ for y in range (self .rows - 1 , 0 , - 1 ):
93
+ self [x , y ] = self [x , y - 1 ]
94
+ self [x , 0 ] = last_pixel
95
+ if self ._auto_write :
96
+ self .show ()
97
+
98
+ def shift_down (self , rotate = False ):
99
+ """
100
+ Shift all pixels down
101
+
102
+ :param rotate: (Optional) Rotate the shifted pixels to top (default=False)
103
+ """
104
+ for x in range (0 , self .columns ):
105
+ last_pixel = self [x , 0 ] if rotate else 0
106
+ for y in range (0 , self .rows - 1 ):
107
+ self [x , y ] = self [x , y + 1 ]
108
+ self [x , self .rows - 1 ] = last_pixel
109
+ if self ._auto_write :
110
+ self .show ()
111
+
53
112
class Matrix16x8 (Matrix8x8 ):
54
113
"""The matrix wing."""
114
+ columns = 16
115
+ rows = 8
116
+
55
117
def pixel (self , x , y , color = None ):
56
118
"""Get or set the color of a given pixel."""
57
119
if not 0 <= x <= 15 :
@@ -63,7 +125,7 @@ def pixel(self, x, y, color=None):
63
125
y += 8
64
126
return super ()._pixel (y , x , color )
65
127
66
- class MatrixBackpack16x8 (Matrix8x8 ):
128
+ class MatrixBackpack16x8 (Matrix16x8 ):
67
129
"""A double matrix backpack."""
68
130
def pixel (self , x , y , color = None ):
69
131
"""Get or set the color of a given pixel."""
0 commit comments