-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheffect_lighthouse.py
95 lines (73 loc) · 2.16 KB
/
effect_lighthouse.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from effect_base import Effect
white = (1.0, 1.0, 1.0)
off = (0, 0, 0)
loop = [0, 1, 2, 3, 4, 9, 14, 19, 24, 23, 22, 21, 20, 15, 10, 5]
steps = (
[[0, 0], [1, 1]],
[[0, 1]],
[[0, 2], [1, 2]],
[[0, 3]],
[[0, 4], [1, 3]],
[[1, 4]],
[[2, 4], [2, 3]],
[[3, 4]],
[[4, 4], [3, 3]],
[[4, 3]],
[[4, 2], [3, 2]],
[[4, 1]],
[[4, 0], [3, 1]],
[[3, 0]],
[[2, 0], [2, 1]],
[[1, 0]]
)
def scaleLightVector(s, v):
return (max(v[0] * s, 0), max(v[1] * s, 0), max(v[2] * s, 0))
class LighthousePatternOld(Effect):
def __init__(self):
super().__init__()
self.transition_length = [[0.4] * 5 for _ in range(5)]
self.step = 0
self.all_off()
def setLantern(self, index, color):
self.pattern[index // 5][index % 5] = color
def all_off(self):
for i in range(25):
self.setLantern(i, off)
def next_frame(self):
# called every 0.4 seconds
self.step += 1
looplen = len(loop)
for i in range(looplen):
self.setLantern(
loop[i],
scaleLightVector(
1 - (((self.step - i) % looplen) / looplen), white
)
)
class LighthousePattern(Effect):
def __init__(self):
super().__init__()
self.transition_length = [[0.4] * 5 for _ in range(5)]
self.step = 1
self.last_step = 0
self.all_off()
def all_off(self):
for i in range(25):
self.setLantern(i, off)
def setLantern(self, index, color):
self.pattern[index // 5][index % 5] = color
def set_lantern(self, idx, color, transition):
self.pattern[idx[0]][idx[1]] = color
self.transition_length[idx[0]][idx[1]] = transition
def next_frame(self):
# called every 0.4 seconds
self.last_step = self.step
self.step += 1
if self.step >= len(steps):
self.step = 0
lit = steps[self.step]
dark = steps[self.last_step]
for idx in lit:
self.set_lantern(idx, white, 0.2)
for idx in dark:
self.set_lantern(idx, (0.1, 0.1, 0.1), 5)