-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scintillate.cpp
50 lines (36 loc) · 1.23 KB
/
Scintillate.cpp
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
#ifndef Scintillate_h
#define Scintillate_h
#include "FastLED.h"
#include "Effect.cpp"
#define CONCURRENT_SPARKLES (NUM_LEDS/20)
struct Sparkle {
uint8_t x, y;
uint8_t colourIndex;
};
static CRGB sparklePalette[] = {CRGB::Black, CRGB::White, CRGB::DarkRed};
class Scintillate : public Effect {
private:
bool soundReactive;
uint8_t brightness;
Sparkle sparkles[CONCURRENT_SPARKLES];
public:
Scintillate(CRGB *leds) : Effect(leds, "Scintillate"), soundReactive(false), brightness(0) {
}
virtual void draw(EffectControls controls) {
for (int i = 0; i < CONCURRENT_SPARKLES; i++) {
if (sparkles[i].colourIndex == 0) {
if (random() > 128) {
sparkles[i].x = random(WIDTH);
sparkles[i].y = random(HEIGHT);
sparkles[i].colourIndex = 1;
}
} else if (sparkles[i].colourIndex == 2) {
sparkles[i].colourIndex = 0;
} else {
sparkles[i].colourIndex++;
}
pixel(sparkles[i].x, sparkles[i].y) = CRGB(sparklePalette[sparkles[i].colourIndex]);
}
}
};
#endif