Skip to content

Commit 2fb6c7d

Browse files
adjusting code to fit within linter guidelines
1 parent 6a10a6f commit 2fb6c7d

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

adafruit_led_animation/color.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@
2929
except (ImportError, ModuleNotFoundError):
3030

3131
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
3344
pos = pos - ((pos // 256) * 256)
3445
shift1 = 0
3546
shift2 = 0
@@ -44,9 +55,9 @@ def colorwheel(pos):
4455
pos -= 170
4556
shift1 = 16
4657
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)
5061

5162

5263
RED = (255, 0, 0)

adafruit_led_animation/group.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ def animate(self, show=True):
146146
for member in self._members:
147147
if isinstance(member, Animation):
148148
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)
153150
last_strip = member.pixel_object
154151
else:
155152
member.show()
@@ -161,6 +158,17 @@ def animate(self, show=True):
161158
ret = True
162159
return ret
163160

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+
164172
@property
165173
def color(self):
166174
"""

0 commit comments

Comments
 (0)