forked from dwyerk/blinkenlights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
penner.py
37 lines (34 loc) · 1.2 KB
/
penner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from bibliopixel.animation import BaseStripAnim
from bibliopixel import colors
class OutBounce(BaseStripAnim):
def __init__(self, led, duration=100, start=0, end=-1):
# The base class MUST be initialized by calling super like this
super(OutBounce, self).__init__(led, start, end)
self.last_idx = None
self.duration = duration
def step(self, amt=1):
#self._led.all_off()
self._led.setOff(self.last_idx)
t = self._step
c = self._led.numLEDs
b = 0
t = float(t) / self.duration
if t < 1 / 2.75:
step_modifier = 7.5625 * t * t
elif t < 2 / 2.75:
t = t - (1.5 / 2.75)
step_modifier = 7.5625 * t * t + 0.75
elif t < 2.5 / 2.75:
t = t - (2.25 / 2.75)
step_modifier = 7.5625 * t * t + 0.9375
else:
t = t - (2.625 / 2.75)
step_modifier = 7.5625 * t * t + 0.984375
idx = c * step_modifier + b
idx = int(idx)
#print "step is", self._step, "idx is", idx
self._led.set(idx, colors.Red)
if idx > self._led.numLEDs:
self._step = 0
self._step += amt
self.last_idx = idx