2525================
2626
2727"""
28-
2928from adafruit_ht16k33 .ht16k33 import HT16K33
3029
3130__version__ = "0.0.0-auto.0"
3231__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
3332
3433class Matrix8x8 (HT16K33 ):
3534 """A single matrix."""
35+ _columns = 8
36+ _rows = 8
37+
3638 def pixel (self , x , y , color = None ):
3739 """Get or set the color of a given pixel."""
3840 if not 0 <= x <= 7 :
@@ -50,8 +52,91 @@ def __setitem__(self, key, value):
5052 x , y = key
5153 self .pixel (x , y , value )
5254
55+ #pylint: disable=too-many-branches
56+ def shift (self , x , y , rotate = False ):
57+ """
58+ Shift pixels by x and y
59+
60+ :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
61+ """
62+ if x > 0 : # Shift Right
63+ for _ in range (x ):
64+ for row in range (0 , self .rows ):
65+ last_pixel = self [self .columns - 1 , row ] if rotate else 0
66+ for col in range (self .columns - 1 , 0 , - 1 ):
67+ self [col , row ] = self [col - 1 , row ]
68+ self [0 , row ] = last_pixel
69+ elif x < 0 : # Shift Left
70+ for _ in range (- x ):
71+ for row in range (0 , self .rows ):
72+ last_pixel = self [0 , row ] if rotate else 0
73+ for col in range (0 , self .columns - 1 ):
74+ self [col , row ] = self [col + 1 , row ]
75+ self [self .columns - 1 , row ] = last_pixel
76+ if y > 0 : # Shift Up
77+ for _ in range (y ):
78+ for col in range (0 , self .columns ):
79+ last_pixel = self [col , self .rows - 1 ] if rotate else 0
80+ for row in range (self .rows - 1 , 0 , - 1 ):
81+ self [col , row ] = self [col , row - 1 ]
82+ self [col , 0 ] = last_pixel
83+ elif y < 0 : # Shift Down
84+ for _ in range (- y ):
85+ for col in range (0 , self .columns ):
86+ last_pixel = self [col , 0 ] if rotate else 0
87+ for row in range (0 , self .rows - 1 ):
88+ self [col , row ] = self [col , row + 1 ]
89+ self [col , self .rows - 1 ] = last_pixel
90+ if self ._auto_write :
91+ self .show ()
92+ #pylint: enable=too-many-branches
93+
94+ def shift_right (self , rotate = False ):
95+ """
96+ Shift all pixels right
97+
98+ :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
99+ """
100+ self .shift (1 , 0 , rotate )
101+
102+ def shift_left (self , rotate = False ):
103+ """
104+ Shift all pixels left
105+
106+ :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
107+ """
108+ self .shift (- 1 , 0 , rotate )
109+
110+ def shift_up (self , rotate = False ):
111+ """
112+ Shift all pixels up
113+
114+ :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
115+ """
116+ self .shift (0 , 1 , rotate )
117+
118+ def shift_down (self , rotate = False ):
119+ """
120+ Shift all pixels down
121+
122+ :param rotate: (Optional) Rotate the shifted pixels to top (default=False)
123+ """
124+ self .shift (0 , - 1 , rotate )
125+
126+ @property
127+ def columns (self ):
128+ """Read-only property for number of columns"""
129+ return self ._columns
130+
131+ @property
132+ def rows (self ):
133+ """Read-only property for number of rows"""
134+ return self ._rows
135+
53136class Matrix16x8 (Matrix8x8 ):
54137 """The matrix wing."""
138+ _columns = 16
139+
55140 def pixel (self , x , y , color = None ):
56141 """Get or set the color of a given pixel."""
57142 if not 0 <= x <= 15 :
@@ -63,7 +148,7 @@ def pixel(self, x, y, color=None):
63148 y += 8
64149 return super ()._pixel (y , x , color )
65150
66- class MatrixBackpack16x8 (Matrix8x8 ):
151+ class MatrixBackpack16x8 (Matrix16x8 ):
67152 """A double matrix backpack."""
68153 def pixel (self , x , y , color = None ):
69154 """Get or set the color of a given pixel."""
0 commit comments