-
Notifications
You must be signed in to change notification settings - Fork 1
/
effect_template.py
42 lines (33 loc) · 1.58 KB
/
effect_template.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
from typing import Any
def frame_max() -> int:
"""
Set the number of frames to generate
"""
return 1
def frame_time(frame: int) -> float:
"""
!!! Only takes effect in visualizers compatible with GSD6338/XmasTree/#4 (including this one)
Set the frame time of this effect (1/frame rate)
you can vary this number each frame to make some frames last longer
This may not be perfectly accurate in the visualizer
(and probably won't be on the actual tree either)
"""
_ = frame
return 1/30 # just run at a constant 30FPS by default
def run(positions: list[dict], frame: int, storage: Any) -> (list[dict], Any):
"""
positions - are given to you as a list of dictionaries for each LED
[ {x, y, z}, {'x': -0.2, 'y': 1.3, 'z': 0.8}, ... ]
the length of the list is the number of LEDs in the tree
the tree is centered at x=0 y=0, z goes from 0 up
frame - gives you the current frame number
starts at 1, ends at frame_max(), inclusive
storage - you can set it to whatever you want, will be returned to you next frame
it's a way of keeping data you might need to access across multiple frames
return a list of normalized RGB values
[ {r, g, b}, {'r': 0.2, 'g': 0.7, 'b': 1}, ... ]
one dictionary per LED - the same length as positions
"""
_ = frame
rgb = [{'r': 0, 'g': 0, 'b': 0} for _ in positions] # this template is a valid effect, will set all LEDs to black
return rgb, storage