-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheffects.h
More file actions
214 lines (175 loc) · 5.39 KB
/
Copy patheffects.h
File metadata and controls
214 lines (175 loc) · 5.39 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#pragma once
#include "particle.h"
#include "virtual_strip.h"
void addGlitter(CRGB color=CRGB::White, PenMode pen=Draw)
{
addParticle(new Particle(random16(), color, pen, 128));
}
void addSpark(CRGB color=CRGB::White, PenMode pen=Draw)
{
Particle *particle = new Particle(random16(), color, pen, 64);
uint8_t r = random8();
if (r > 128)
particle->velocity = r;
else
particle->velocity = -(128 + r);
addParticle(particle);
}
void addBeatbox(CRGB color=CRGB::White, PenMode pen=Draw)
{
Particle *particle = new Particle(random16(), color, pen, 256, drawBeatbox);
addParticle(particle);
}
void addBubble(CRGB color=CRGB::White, PenMode pen=Draw)
{
Particle *particle = new Particle(random16(), color, pen, 1024, drawPop);
particle->velocity = random16(0, 40) - 20;
addParticle(particle);
}
void addFlash(CRGB color=CRGB::Blue, PenMode pen=Draw)
{
addParticle(new Particle(random16(), color, pen, 256, drawFlash));
}
void addDrop(CRGB color, PenMode pen=Draw)
{
Particle *particle = new Particle(65535, color, pen, 360);
particle->velocity = -500;
particle->gravity = -10;
addParticle(particle);
}
#ifdef UNUSED
void addFireworkAt(uint16_t pos, CRGB color)
{
Particle *p1 = new Particle(pos, CRGB::White, 20);
Particle *p2 = new Particle(pos, CRGB::White, 20);
Particle *p3 = new Particle(pos, CRGB::White, 20);
p1->velocity = 0;
p2->velocity = 40 + random8(40);
p3->velocity = -40 - random8(40);
addParticle(p1);
addParticle(p2);
addParticle(p3);
for (int i=0; i<20; i++)
{
Particle *p = new Particle(pos, color, 60);
// p->palette = PartyColors_p;
uint16_t vel = random8();
if (vel < 128)
p->velocity = -2 * vel;
else
p->velocity = 2 * (vel - 128);
addParticle(p);
}
}
void addFirework(fract8 chance)
{
if( random8() >= chance)
return;
uint8_t hue = random8();
CRGB color = CHSV(hue, 255, 255);
addFireworkAt(random16(), color);
}
void explode(class Particle *particle)
{
addFireworkAt(particle->position, particle->color);
}
void throwFirework(fract8 chance)
{
if( random8() > chance)
return;
CRGB color = CHSV(random8(), 255, 255);
Particle *particle = new Particle(0, color, 100);
particle->velocity = 700 + random16(250);
particle->gravity = -10;
particle->die_fn = explode;
addParticle(particle);
}
#endif
class Effects {
public:
EffectMode effect=None;
PenMode pen=Draw;
BeatPulse beat;
uint8_t chance;
void load(EffectParameters ¶ms) {
this->effect = params.effect;
this->pen = params.pen;
this->beat = params.beat;
this->chance = params.chance;
}
void update(VirtualStrip *strip, BeatFrame_24_8 beat_frame, BeatPulse beat_pulse) {
if (!this->beat || beat_pulse & this->beat) {
if (random8() <= this->chance) {
CRGB color = strip->palette_color(random8());
switch (this->effect) {
case None:
break;
case Glitter:
addGlitter(color, this->pen);
break;
case Beatbox1:
case Beatbox2:
addBeatbox(color, this->pen);
if (this->effect == Beatbox2)
addBeatbox(color, this->pen);
break;
case Bubble:
addBubble(color, this->pen);
break;
case Spark:
addSpark(color, this->pen);
break;
case Flash:
addFlash(CRGB::White, this->pen);
break;
}
}
}
this->animate(beat_frame, beat_pulse);
}
void animate(BeatFrame_24_8 frame, uint8_t beat_pulse) {
unsigned int len = particles.length();
for (unsigned i=len; i > 0; i--) {
Particle *particle = particles[i-1];
particle->update(frame);
if (particle->age > particle->lifetime) {
delete particle;
particles.erase(i-1);
continue;
}
}
}
void draw(CRGB strip[], uint8_t num_leds) {
uint8_t len = particles.length();
for (uint8_t i=0; i<len; i++) {
Particle *particle = particles[i];
particle->drawFn(particle, strip, num_leds);
}
}
};
typedef struct {
EffectParameters params;
ControlParameters control;
} EffectDef;
static const EffectDef gEffects[] STATIC_MEM = {
{{None}, {LongDuration}},
{{Flash, Brighten, Beat, 40}, {MediumDuration, MediumEnergy}},
{{Flash, Darken, TwoBeats, 40}, {MediumDuration, MediumEnergy}},
{{Flash, Brighten, Measure}, {ShortDuration, HighEnergy}},
{{Flash, Brighten, Phrase}, {MediumDuration, HighEnergy}},
{{Flash, Darken, Measure}, {ShortDuration, LowEnergy}},
{{Glitter, Brighten, Eighth, 40}, {ShortDuration, LowEnergy}},
{{Glitter, Brighten, Eighth, 80}, {MediumDuration, MediumEnergy}},
{{Glitter, Brighten, Eighth, 40}, {MediumDuration, HighEnergy}},
{{Glitter, Darken, Eighth, 40}, {MediumDuration, LowEnergy}},
{{Glitter, Draw, Eighth, 10}, {LongDuration, LowEnergy}},
{{Glitter, Draw, Eighth, 120}, {MediumDuration, LowEnergy}},
{{Glitter, Invert, Eighth, 40}, {ShortDuration, LowEnergy}},
{{Beatbox2, Black}, {MediumDuration, LowEnergy}},
{{Beatbox2, Draw}, {ShortDuration, HighEnergy}},
{{Bubble, Darken}, {MediumDuration, LowEnergy}},
{{Bubble, Brighten}, {MediumDuration, LowEnergy}},
{{Glitter, Darken, Eighth, 120}, {MediumDuration, LowEnergy}},
{{Glitter, Flicker, Eighth, 120}, {MediumDuration, LowEnergy}},
};
const uint8_t gEffectCount = ARRAY_SIZE(gEffects);