Skip to content

Commit a90235b

Browse files
committed
Add tail_length exception, update example imports.
1 parent 063b14b commit a90235b

File tree

4 files changed

+50
-61
lines changed

4 files changed

+50
-61
lines changed

adafruit_led_animation/animation/comet.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ class Comet(Animation):
5757
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
5858
:param int tail_length: The length of the comet. Defaults to 10. Cannot exceed the number of
5959
pixels present in the pixel object, e.g. if the strip is 30 pixels
60-
long, the ``tail_length`` cannot exceed 30 pixels.
60+
long, the ``tail_length`` cannot exceed 30 pixels, or, in the case of a
61+
pixel mapped grid, if the width of the grid is 13 pixels, a horizontal
62+
comet tail cannot exceed 13 pixels. To find the lenth of the
63+
``pixel_object``, include a ``print(len(PIXEL_OBJECT_NAME))`` in your
64+
code anywhere after the object creation, where ``PIXEL_OBJECT_NAME`` is
65+
the name assigned to the object, such as ``pixels``.
6166
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
6267
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
6368
"""
@@ -73,6 +78,10 @@ def __init__(
7378
bounce=False,
7479
name=None,
7580
):
81+
if tail_length > len(pixel_object):
82+
raise ValueError(
83+
"Tail length must be less than the length of the pixel_object."
84+
)
7685
self._tail_length = tail_length + 1
7786
self._color_step = 0.9 / tail_length
7887
self._color_offset = 0.1

examples/led_animation_all_animations.py

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import board
1010
import neopixel
1111

12-
import adafruit_led_animation.animation.blink as blink_animation
13-
import adafruit_led_animation.animation.sparklepulse as sparklepulse_animation
14-
import adafruit_led_animation.animation.comet as comet_animation
15-
import adafruit_led_animation.animation.chase as chase_animation
16-
import adafruit_led_animation.animation.pulse as pulse_animation
17-
import adafruit_led_animation.animation.sparkle as sparkle_animation
18-
import adafruit_led_animation.animation.rainbowchase as rainbowchase_animation
19-
import adafruit_led_animation.animation.rainbowsparkle as rainbowsparkle_animation
20-
import adafruit_led_animation.animation.rainbowcomet as rainbowcomet_animation
21-
import adafruit_led_animation.animation.solid as solid_animation
22-
import adafruit_led_animation.animation.colorcycle as colorcycle_animation
23-
import adafruit_led_animation.animation.rainbow as rainbow_animation
12+
from adafruit_led_animation.animation.blink import Blink
13+
from adafruit_led_animation.animation.sparklepulse import SparklePulse
14+
from adafruit_led_animation.animation.comet import Comet
15+
from adafruit_led_animation.animation.chase import Chase
16+
from adafruit_led_animation.animation.pulse import Pulse
17+
from adafruit_led_animation.animation.sparkle import Sparkle
18+
from adafruit_led_animation.animation.rainbowchase import RainbowChase
19+
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
20+
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
21+
from adafruit_led_animation.animation.solid import Solid
22+
from adafruit_led_animation.animation.colorcycle import ColorCycle
23+
from adafruit_led_animation.animation.rainbow import Rainbow
2424
from adafruit_led_animation.sequence import AnimationSequence
2525
from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE, MAGENTA, ORANGE
2626

@@ -31,30 +31,18 @@
3131

3232
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
3333

34-
blink = blink_animation.Blink(pixels, speed=0.5, color=JADE)
35-
colorcycle = colorcycle_animation.ColorCycle(
36-
pixels, speed=0.4, colors=[MAGENTA, ORANGE]
37-
)
38-
comet = comet_animation.Comet(
39-
pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True
40-
)
41-
chase = chase_animation.Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
42-
pulse = pulse_animation.Pulse(pixels, speed=0.1, period=3, color=AMBER)
43-
sparkle = sparkle_animation.Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10)
44-
solid = solid_animation.Solid(pixels, color=JADE)
45-
rainbow = rainbow_animation.Rainbow(pixels, speed=0.1, period=2)
46-
sparkle_pulse = sparklepulse_animation.SparklePulse(
47-
pixels, speed=0.1, period=3, color=JADE
48-
)
49-
rainbow_comet = rainbowcomet_animation.RainbowComet(
50-
pixels, speed=0.1, tail_length=7, bounce=True
51-
)
52-
rainbow_chase = rainbowchase_animation.RainbowChase(
53-
pixels, speed=0.1, size=3, spacing=2, wheel_step=8
54-
)
55-
rainbow_sparkle = rainbowsparkle_animation.RainbowSparkle(
56-
pixels, speed=0.1, num_sparkles=15
57-
)
34+
blink = Blink(pixels, speed=0.5, color=JADE)
35+
colorcycle = ColorCycle(pixels, speed=0.4, colors=[MAGENTA, ORANGE])
36+
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
37+
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
38+
pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER)
39+
sparkle = Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10)
40+
solid = Solid(pixels, color=JADE)
41+
rainbow = Rainbow(pixels, speed=0.1, period=2)
42+
sparkle_pulse = SparklePulse(pixels, speed=0.1, period=3, color=JADE)
43+
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True)
44+
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, wheel_step=8)
45+
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15)
5846

5947

6048
animations = AnimationSequence(

examples/led_animation_gridmap.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import board
1111
import neopixel
1212

13-
import adafruit_led_animation.animation.comet as comet_animation
14-
import adafruit_led_animation.animation.rainbowcomet as rainbowcomet_animation
15-
import adafruit_led_animation.animation.rainbowchase as rainbowchase_animation
16-
import adafruit_led_animation.animation.chase as chase_animation
17-
import adafruit_led_animation.animation.rainbow as rainbow_animation
13+
from adafruit_led_animation.animation.comet import Comet
14+
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
15+
from adafruit_led_animation.animation.rainbowchase import RainbowChase
16+
from adafruit_led_animation.animation.chase import Chase
17+
from adafruit_led_animation.animation.rainbow import Rainbow
1818
from adafruit_led_animation.sequence import AnimationSequence
1919
from adafruit_led_animation import helper
2020
from adafruit_led_animation.color import PURPLE, JADE, AMBER
@@ -29,25 +29,19 @@
2929
pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False)
3030
)
3131

32-
comet_h = comet_animation.Comet(
32+
comet_h = Comet(
3333
pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=3, bounce=True
3434
)
35-
comet_v = comet_animation.Comet(
36-
pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True
37-
)
38-
chase_h = chase_animation.Chase(
39-
pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE
40-
)
41-
rainbow_chase_v = rainbowchase_animation.RainbowChase(
35+
comet_v = Comet(pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True)
36+
chase_h = Chase(pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE)
37+
rainbow_chase_v = RainbowChase(
4238
pixel_wing_vertical, speed=0.1, size=3, spacing=2, wheel_step=8
4339
)
44-
rainbow_comet_v = rainbowcomet_animation.RainbowComet(
40+
rainbow_comet_v = RainbowComet(
4541
pixel_wing_vertical, speed=0.1, tail_length=7, bounce=True
4642
)
47-
rainbow_v = rainbow_animation.Rainbow(pixel_wing_vertical, speed=0.1, period=2)
48-
rainbow_chase_h = rainbowchase_animation.RainbowChase(
49-
pixel_wing_horizontal, speed=0.1, size=3, spacing=3
50-
)
43+
rainbow_v = Rainbow(pixel_wing_vertical, speed=0.1, period=2)
44+
rainbow_chase_h = RainbowChase(pixel_wing_horizontal, speed=0.1, size=3, spacing=3)
5145

5246
animations = AnimationSequence(
5347
rainbow_v,

examples/led_animation_simpletest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"""
1010
import board
1111
import neopixel
12-
import adafruit_led_animation.animation.comet as comet_animation
13-
import adafruit_led_animation.animation.chase as chase_animation
12+
from adafruit_led_animation.animation.comet import Comet
13+
from adafruit_led_animation.animation.chase import Chase
1414
from adafruit_led_animation.sequence import AnimationSequence
1515
from adafruit_led_animation.color import PURPLE, WHITE
1616

@@ -21,10 +21,8 @@
2121

2222
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
2323

24-
comet = comet_animation.Comet(
25-
pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True
26-
)
27-
chase = chase_animation.Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
24+
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
25+
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
2826

2927
animations = AnimationSequence(comet, chase, advance_interval=5)
3028

0 commit comments

Comments
 (0)