Skip to content

Commit

Permalink
fill from center animation
Browse files Browse the repository at this point in the history
  • Loading branch information
longjos committed Jul 15, 2014
1 parent 36a708e commit 1072e33
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 18 additions & 1 deletion raspledstrip/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,21 @@ def __init__(self, led_driver, strobe_color, start=0, end=0):

def step(self, step_amount=1):
self._led.fill(self._color) if self._step % 2 else self._led.all_off()
self._step += step_amount
self._step += step_amount


class FillFromCenter(BaseAnimation):
def __init__(self, led_driver, fill_color, start=0, end=0):
self._strip_length = led_driver.lastIndex
self._center_point = int(self._strip_length/2)
self._color = fill_color
super(FillFromCenter, self).__init__(led_driver, start, end)

def step(self, step_amount=1):
if self._step > self._led.lastIndex:
self._step = 1
self._led.fillOff()
self._led.set(self._center_point + self._step, self._color)
self._led.set(self._center_point - self._step, self._color)
self._step += 1

11 changes: 7 additions & 4 deletions test_animation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import time
from raspledstrip.ledstrip import LEDStrip
from raspledstrip.animation import AlertStrobe
from raspledstrip.animation import AlertStrobe, FillFromCenter
from raspledstrip.color import Color

led_driver = LEDStrip(36, True)
led_driver.all_off()

alert_animation = AlertStrobe(led_driver, Color(255.0, 0, 0, 1.0))
alert_animation.run(1, .01, 200)

alert_color = Color(255, 0, 0, 1.0)
alert_animation = AlertStrobe(led_driver, alert_color)
alert_animation.run(1, 20, 24)
fill_animation = FillFromCenter(led_driver, alert_color)
fill_animation.run(1, 30, 200)
led_driver.all_off()

0 comments on commit 1072e33

Please sign in to comment.