-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.h
More file actions
65 lines (43 loc) · 1.24 KB
/
Animation.h
File metadata and controls
65 lines (43 loc) · 1.24 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <NeoPixelBus.h>
class Color8Bit
{
public:
uint8_t h; // Hue
uint8_t s; // Saturation
uint8_t b; // Brightness
Color8Bit() : h(0), s(255), b(0) {}
};
class AnimationContext
{
public:
const unsigned short numLeds;
Color8Bit* const leds;
const uint8_t edgeLength;
Color8Bit* const edge1;
Color8Bit* const edge2;
Color8Bit* const edge3;
float brightnessFactor;
long timeSinceBeat; // microseconds
AnimationContext(int numLeds, int edgeLength) :
numLeds(numLeds),
leds(new Color8Bit[numLeds]),
edgeLength(edgeLength),
edge1(leds),
edge2(edge1 + edgeLength),
edge3(edge2 + edgeLength),
brightnessFactor(1.0),
timeSinceBeat(0)
{}
};
class Animation
{
public:
Animation* next;
Animation() : next(nullptr) {}
virtual void prepare(AnimationContext& ctx) {}
/**
* tpf: Time per frame in microseconds
*/
virtual void update(AnimationContext& ctx, long tpf, bool beat) = 0;
};