Skip to content

Commit

Permalink
Pull end bounds-checking up into BaseAnimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Packetslave committed Oct 7, 2013
1 parent 1c48864 commit 3491589
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ class BaseAnimation(object):
def __init__(self, led, start, end):
self._led = led
self._start = start

self._end = end
self._size = end - start + 1
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

self._size = self._end - self._start + 1
self._step = 0

def step(self):
Expand All @@ -29,9 +33,6 @@ def __init__(self, led, start=0, end=0):
super(Rainbow, self).__init__(led, start, end)

def step(self):
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

for i in range(self._size):
color = (i + self._step) % 384
self._led.set(self._start + i, wheel_color(color))
Expand All @@ -48,9 +49,6 @@ def __init__(self, led, start=0, end=0):
super(RainbowCycle, self).__init__(led, start, end)

def step(self):
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

for i in range(self._size):
color = (i * (384 / self._size) + self._step) % 384
self._led.set(self._start + i, wheel_color(color))
Expand All @@ -68,9 +66,6 @@ def __init__(self, led, color, start=0, end=0):
self._color = color

def step(self):
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

if self._step == 0:
self._led.fillOff()

Expand All @@ -89,9 +84,6 @@ def __init__(self, led, color, start=0, end=0):
self._color = color

def step(self):
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

if self._step == 0:
self._led.setOff(self._end)
else:
Expand All @@ -116,9 +108,6 @@ def __init__(self, led, color, tail=2, fade=0.75, start=0, end=0):
self._last = 0

def step(self):
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

self._tail += 1 # makes tail math later easier
if self._tail >= self._size / 2:
self._tail = (self._size / 2) - 1
Expand Down Expand Up @@ -183,9 +172,6 @@ def __init__(self, led, color, cycles, start=0, end=0):
self._cycles = cycles

def step(self):
if self._end == 0 or self._end > self._led.lastIndex:
self._end = self._led.lastIndex

for i in range(self._size):
y = math.sin(
math.pi *
Expand Down

0 comments on commit 3491589

Please sign in to comment.