-
Notifications
You must be signed in to change notification settings - Fork 4
/
Matrix.cpp
62 lines (53 loc) · 1.5 KB
/
Matrix.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
#include "Matrix.h"
Matrix::Matrix(Strip *strip, AudioChannel *audioChannel, State *state) : Fx(strip, audioChannel, state) {
audioTrigger = new AudioTrigger(audioChannel);
up = new bool[strip->size()];
down = new bool[strip->size()];
for (uint16_t i = 0; i < strip->size() ; i++) {
up[i] = down[i] = false;
}
}
Matrix::~Matrix() {
delete audioTrigger;
delete[] up;
delete[] down;
}
void Matrix::reset() {
clear();
countDown = DOWN_PERIOD;
countUp = UP_PERIOD;
for (uint16_t i = 0; i < strip->size(); i++) {
up[i] = down[i] = false;
}
audioTrigger->reset();
}
void Matrix::loop() {
audioTrigger->loop();
addFromTop();
addFromBottom();
show();
}
void Matrix::addFromTop() {
if (--countDown == 0) {
// down[strip->last()] = !down[strip->last() - 1] && random8() < DOWN_PROBABILITY;
down[strip->last()] = !down[strip->last() - 1] && random8() < 50 * state->parabolicFxSpeed;
for (int i = 0; i < strip->last(); i++) {
down[i] = down[i + 1];
}
countDown = DOWN_PERIOD;
}
}
void Matrix::addFromBottom() {
if (--countUp == 0) {
up[0] = audioTrigger->triggered(.5);
for (int i = strip->last(); i > 0; i--) {
up[i] = up[i - 1];
}
countUp = UP_PERIOD;
}
}
void Matrix::show() {
for (int i = 0; i < strip->size() ; i++) {
strip->paint(i, (up[i] ? UP_COLOR : CRGB::Black) + (down[i] ? DOWN_COLOR : CRGB::Black), false);
}
}