-
Notifications
You must be signed in to change notification settings - Fork 6
/
clean.cpp
118 lines (106 loc) · 3.01 KB
/
clean.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
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
#include "clean.h"
//---------------------------------------------- Classes for strip clearing ----------------------------------------------
bool clr::fadeAll(uint8_t val) {
bool finish = true;
for (uint16_t i = 0; i < strip.numPixels(); ++i) {
if (!fade(i, val)) finish = false;
}
return finish;
}
bool clr::fade(uint16_t index, uint8_t val) {
COLOR c = strip.getPixelColor(index);
uint8_t bound = 0;
for (int8_t s = 16; s >= 0; s -= 8) {
int32_t cc = c >> s; // The color component (red, green or blue)
cc &= 0xff;
cc -= int(val);
if (cc < 0) {
cc = 0;
bound ++;
}
uint32_t mask = 0xff; mask <<= s; mask = ~mask;
cc <<= s;
c &= mask;
c |= cc;
}
strip.setPixelColor(index, c);
return (bound >= 3);
}
bool clr::isComplete(void) {
return complete;
}
// --------------------------------------------- Clear the strip from the ether side --------------------------------------
void clearSide::init(void) {
complete = false;
color = strip.wheel(Random(256));
fwd = Random(2);
if (fwd)
index = 0;
else
index = strip.numPixels() - 1;
}
void clearSide::show(void) {
if (fwd) {
if (index < int(strip.numPixels())) {
strip.setPixelColor(index, color);
if (index > 0) strip.setPixelColor(index-1, 0);
}
++index;
complete = (index >= int(strip.numPixels()));
} else {
if (index >= 0) {
strip.setPixelColor(index, color);
if (index < int(strip.numPixels() - 1)) strip.setPixelColor(index+1, 0);
}
--index;
complete = (index < 0);
}
}
// --------------------------------------------- Clear the strip from the center to both ends -----------------------------
void clearCntr::init(void) {
complete = false;
color = strip.wheel(Random(256));
l = strip.numPixels() / 2;
r = l + 1;
}
void clearCntr::show(void) {
if (r < int(strip.numPixels())) {
strip.setPixelColor(r, color);
if (r > 0) strip.setPixelColor(r-1, 0);
}
++r;
if (l >= 0) {
strip.setPixelColor(l, color);
if (l < int(strip.numPixels() - 1)) strip.setPixelColor(l+1, 0);
}
--l;
complete = (l < 0);
}
// --------------------------------------------- Clear the strip by 'eating' the pixels from the center -------------------
void eatCntr::show(void) {
int n = strip.numPixels();
int c = n / 2;
for (int i = c; i > 0; --i) {
COLOR c = strip.getPixelColor(i-1);
strip.setPixelColor(i, c);
}
for (int i = c; i < n-1; ++i) {
COLOR c = strip.getPixelColor(i+1);
strip.setPixelColor(i, c);
}
strip.setPixelColor(0, 0);
strip.setPixelColor(n-1, 0);
--remain;
complete = (remain <= 0);
}
//---------------------------------------------- Clear the strip by deviding it by 2 ------------------------------------
void clearHalf::init(void) {
complete = false;
one_step = strip.numPixels() / 2;
}
void clearHalf::show(void) {
for (uint16_t i = 0; i < strip.numPixels(); i += one_step) {
if (i > 0 || (one_step == 1)) strip.setPixelColor(i, 0);
}
complete = ((one_step >>= 1) == 0);
}