Skip to content

Commit cb18147

Browse files
authored
Merge pull request #22 from kattni/comet-tail-exception
Add tail_length exception, update example imports.
2 parents 063b14b + c7d1950 commit cb18147

File tree

6 files changed

+89
-75
lines changed

6 files changed

+89
-75
lines changed

adafruit_led_animation/animation/comet.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class Comet(Animation):
5555
:param pixel_object: The initialised LED object.
5656
:param float speed: Animation speed in seconds, e.g. ``0.1``.
5757
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
58-
:param int tail_length: The length of the comet. Defaults to 10. Cannot exceed the number of
59-
pixels present in the pixel object, e.g. if the strip is 30 pixels
60-
long, the ``tail_length`` cannot exceed 30 pixels.
58+
:param int tail_length: The length of the comet. Defaults to 25% of the length of the
59+
``pixel_object``. Automatically compensates for a minimum of 2 and a
60+
maximum of the length of the ``pixel_object``.
6161
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
6262
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
6363
"""
@@ -68,12 +68,16 @@ def __init__(
6868
pixel_object,
6969
speed,
7070
color,
71-
tail_length=10,
71+
tail_length=0,
7272
reverse=False,
7373
bounce=False,
7474
name=None,
7575
):
76-
self._tail_length = tail_length + 1
76+
if tail_length == 0:
77+
tail_length = len(pixel_object) // 4
78+
else:
79+
tail_length = max(2, min(tail_length, len(pixel_object)))
80+
self._tail_length = tail_length
7781
self._color_step = 0.9 / tail_length
7882
self._color_offset = 0.1
7983
self._comet_colors = None

adafruit_led_animation/sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(
9696
self,
9797
*members,
9898
advance_interval=None,
99-
auto_clear=False,
99+
auto_clear=True,
100100
random_order=False,
101101
auto_reset=False,
102102
advance_on_cycle_complete=False,

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_sequence.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
This example uses AnimationsSequence to display multiple animations in sequence, at a five second
3+
interval.
4+
5+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
6+
a different form of NeoPixels.
7+
8+
This example does not work on SAMD21 (M0) boards.
9+
"""
10+
import board
11+
import neopixel
12+
13+
from adafruit_led_animation.animation.blink import Blink
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.sequence import AnimationSequence
18+
from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE
19+
20+
# Update to match the pin connected to your NeoPixels
21+
pixel_pin = board.D6
22+
# Update to match the number of NeoPixels you have connected
23+
pixel_num = 32
24+
25+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
26+
27+
blink = Blink(pixels, speed=0.5, color=JADE)
28+
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
29+
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
30+
pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER)
31+
32+
33+
animations = AnimationSequence(
34+
comet, blink, chase, pulse, advance_interval=5, auto_clear=True,
35+
)
36+
37+
while True:
38+
animations.animate()

examples/led_animation_simpletest.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
"""
2-
This simpletest example repeatedly displays two animations, Comet and Chase, at a five second
3-
interval.
2+
This simpletest example displays the Blink animation.
43
54
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
65
a different form of NeoPixels.
7-
8-
This example does not work on SAMD21 (M0) boards.
96
"""
107
import board
118
import neopixel
12-
import adafruit_led_animation.animation.comet as comet_animation
13-
import adafruit_led_animation.animation.chase as chase_animation
14-
from adafruit_led_animation.sequence import AnimationSequence
15-
from adafruit_led_animation.color import PURPLE, WHITE
9+
from adafruit_led_animation.animation.blink import Blink
10+
from adafruit_led_animation.color import RED
1611

1712
# Update to match the pin connected to your NeoPixels
1813
pixel_pin = board.D6
@@ -21,12 +16,7 @@
2116

2217
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
2318

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)
28-
29-
animations = AnimationSequence(comet, chase, advance_interval=5)
19+
blink = Blink(pixels, speed=0.5, color=RED)
3020

3121
while True:
32-
animations.animate()
22+
blink.animate()

0 commit comments

Comments
 (0)