This repository was archived by the owner on Apr 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimations.py
More file actions
46 lines (43 loc) · 1.68 KB
/
animations.py
File metadata and controls
46 lines (43 loc) · 1.68 KB
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
import time
import math
from random import choice
from lpfx.constants import COLOR_RAINBOW
def wave_effect(controller, direction="horizontal", speed=0.1, duration=5):
start = time.time()
while time.time() - start < duration and controller.running:
for phase in range(8):
for row in range(8):
for col in range(8):
if direction == "horizontal":
val = int(4.5 + 3.5 * math.sin((col + phase) * math.pi / 4))
lit = (7 - row) == val
else:
val = int(4.5 + 3.5 * math.sin((row + phase) * math.pi / 4))
lit = (7 - col) == val
note = row * 16 + col
controller.send_note(note, choice(COLOR_RAINBOW) if lit else 0)
time.sleep(speed)
controller.clear_grid()
def sweep_effect(controller, direction="left", speed=0.05, duration=5):
steps = 8
if direction == "left":
cols = range(8)
elif direction == "right":
cols = reversed(range(8))
elif direction == "up":
rows = reversed(range(8))
else:
rows = range(8)
start = time.time()
while time.time() - start < duration and controller.running:
for step in range(steps):
for row in range(8):
for col in range(8):
note = row * 16 + col
if direction in ["left", "right"]:
lit = col == step
else:
lit = row == step
controller.send_note(note, choice(COLOR_RAINBOW) if lit else 0)
time.sleep(speed)
controller.clear_grid()