forked from evilgeniuslabs/tree-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeteors.h
73 lines (56 loc) · 1.48 KB
/
Meteors.h
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
struct Meteor {
uint8_t angle = random8();
uint8_t level = random8(levelCount);
};
const uint8_t meteorCount = 1;
Meteor meteors[meteorCount];
uint8_t getMeteorLedIndexAndUpdate(uint8_t meteorIndex) {
Meteor meteor = meteors[meteorIndex];
uint8_t i = getNearestToAngleAndLevel(meteor.angle, meteor.level);
EVERY_N_MILLISECONDS(60) {
meteor.level--;
if (meteor.level == 0) {
meteor.level = levelCount;
meteor.angle = random8();
}
else if (meteor.level == levelCount) {
if(random16() > 30000) {
meteor.level = levelCount - 1;
}
}
meteors[meteorIndex] = meteor;
}
if (meteor.level >= levelCount) {
return NUM_LEDS;
}
return i;
}
void whiteMeteors() {
dimAll(220);
EVERY_N_MILLISECONDS(30) {
for (uint8_t meteorIndex = 0; meteorIndex < meteorCount; meteorIndex++) {
uint16_t i = getMeteorLedIndexAndUpdate(meteorIndex);
if(i < NUM_LEDS) {
leds[i] = CRGB(255, 255, 255);
}
}
}
}
void paletteMeteors() {
dimAll(220);
for (uint8_t meteorIndex = 0; meteorIndex < meteorCount; meteorIndex++) {
uint16_t i = getMeteorLedIndexAndUpdate(meteorIndex);
if(i < NUM_LEDS) {
leds[i] = ColorFromPalette(gCurrentPalette, gHue);
}
}
}
void rainbowMeteors() {
dimAll(220);
for (uint8_t meteorIndex = 0; meteorIndex < meteorCount; meteorIndex++) {
uint16_t i = getMeteorLedIndexAndUpdate(meteorIndex);
if(i < NUM_LEDS) {
leds[i] = CHSV(gHue, 255, 255);
}
}
}