-
Notifications
You must be signed in to change notification settings - Fork 0
/
Twinkle.cpp
58 lines (50 loc) · 1.56 KB
/
Twinkle.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
47
48
49
50
51
52
53
54
55
56
57
/*
* Effect implementation for the GauntletII project.
*/
#include "Effect.h"
#define MAX_TWINKS 25
#define OFFSET 0xB000
typedef struct Twink {
short x;
short y;
} Twink;
class Twinkle : public Effect {
private:
short numTwinks;
bool colour;
bool cycleSaturation;
public:
Twinkle(CRGB *leds, int width, int height, bool colour, bool cycleSaturation) :
Effect(leds, width, height),
colour(colour),
cycleSaturation(cycleSaturation),
numTwinks(0) {
}
void start() {
for (uint16_t frame = 0x0000, iterations = 0; iterations < 2250; frame += 0x20, iterations++) {
for (int i = 0; i < width * height; i++) {
if (leds[i]) {
leds[i].fadeToBlackBy(50);
if (!leds[i]) {
numTwinks--;
}
} else {
if (random(56) == 0) {
numTwinks++;
if (colour) {
if (cycleSaturation) {
uint8_t saturation = (sin16(frame + OFFSET) >> 8) + 128;
leds[i] = CHSV(random(255), saturation, 255);
} else {
leds[i] = CHSV(random(255), random(128, 255), 255);
}
} else {
leds[i] = CRGB::White;
}
}
}
}
LEDS.show();
}
}
};