File tree 2 files changed +27
-8
lines changed
2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 29
29
except (ImportError , ModuleNotFoundError ):
30
30
31
31
def colorwheel (pos ):
32
- # ref: https://github.com/adafruit/circuitpython/blob/main/shared-module/rainbowio/__init__.c
32
+ """
33
+ Generate a color from a position value on a color wheel.
34
+ This function maps an input position (0-255) to a color on a
35
+ virtual RGB color wheel. The colors transition smoothly through
36
+ red, green, and blue.
37
+ :param float pos: Position on the color wheel (0-255). Values outside
38
+ this range will be wrapped around.
39
+ :return: color
40
+ """
41
+
42
+ # ref:
43
+ # https://github.com/adafruit/circuitpython/blob/main/shared-module/rainbowio/__init__.c
33
44
pos = pos - ((pos // 256 ) * 256 )
34
45
shift1 = 0
35
46
shift2 = 0
@@ -44,9 +55,9 @@ def colorwheel(pos):
44
55
pos -= 170
45
56
shift1 = 16
46
57
shift2 = 0
47
- p = (int )(pos * 3 )
48
- p = p if (p < 256 ) else 255
49
- return (p << shift1 ) | ((255 - p ) << shift2 )
58
+ pos_new = (int )(pos * 3 )
59
+ pos_new = pos_new if (pos_new < 256 ) else 255
60
+ return (pos_new << shift1 ) | ((255 - pos_new ) << shift2 )
50
61
51
62
52
63
RED = (255 , 0 , 0 )
Original file line number Diff line number Diff line change @@ -146,10 +146,7 @@ def animate(self, show=True):
146
146
for member in self ._members :
147
147
if isinstance (member , Animation ):
148
148
if last_strip != member .pixel_object :
149
- if hasattr (member .pixel_object , "show" ):
150
- member .pixel_object .show ()
151
- elif hasattr (member .pixel_object , "write" ):
152
- member .pixel_object .write ()
149
+ self ._pixel_object_show (member .pixel_object )
153
150
last_strip = member .pixel_object
154
151
else :
155
152
member .show ()
@@ -161,6 +158,17 @@ def animate(self, show=True):
161
158
ret = True
162
159
return ret
163
160
161
+ def _pixel_object_show (self , pixel_object ):
162
+ """
163
+ Show the pixel object. This is a helper function to handle both
164
+ MicroPython and CircuitPython.
165
+ :param pixel_object: The pixel object to show/write to.
166
+ """
167
+ if hasattr (pixel_object , "show" ):
168
+ pixel_object .show ()
169
+ elif hasattr (pixel_object , "write" ):
170
+ pixel_object .write ()
171
+
164
172
@property
165
173
def color (self ):
166
174
"""
You can’t perform that action at this time.
0 commit comments