Extended MatrixEffect to also get RainbowMatrixEffect and RandomMatrixEffect.

Side note: You know you understand C++ when you understand the meaning 
and reason for "MatrixEffect** _columns". ;-)
This commit is contained in:
2019-06-16 12:43:05 +02:00
parent 3edbf6b252
commit e8f3ea3281
3 changed files with 103 additions and 22 deletions

View File

@ -26,12 +26,7 @@ void MatrixEffectColumn::advance() {
void MatrixEffectColumn::draw() {
for(int i=0; i<length; i++) {
CRGB color;
if (i==0) {
color = CRGB(255, 255, 255);
} else {
color = ColorFromPalette((CRGBPalette16)palette_matrix, 255 * (length - i) / length);
}
CRGB color = _getColor(i);
window->setPixel(x, y-i, &color);
}
}
@ -52,21 +47,79 @@ void MatrixEffectColumn::loop() {
}
}
CRGB MatrixEffectColumn::_getColor(uint8_t i) {
CRGB color;
if (i==0) {
color = CRGB(255, 255, 255);
} else {
color = CHSV(83, 255, 255 * (length - i) / length);
}
return color;
}
CRGB RainbowMatrixEffectColumn::_getColor(uint8_t i) {
CRGB color;
if (i==0) {
color = CRGB(255, 255, 255);
} else {
color = CHSV(255 * x / window->width, 255, 255 * (length - i) / length);
}
return color;
}
CRGB RandomMatrixEffectColumn::_getColor(uint8_t i) {
CRGB color;
//Serial.print("RandomMatrixEffectColumn::_getColor, hue="); Serial.println(_hue);
if (i==0) {
color = CRGB(255, 255, 255);
} else {
color = CHSV(_hue, 255, 255 * (length - i) / length);
}
return color;
}
void RandomMatrixEffectColumn::start() {
MatrixEffectColumn::start();
_hue = random8();
}
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
MatrixEffect::MatrixEffect() {
}
void MatrixEffect::start() {
_columns = new MatrixEffectColumn[LED_WIDTH];
for (int i=0; i<LED_WIDTH; i++) _columns[i] = MatrixEffectColumn(window, i);
_columns = new MatrixEffectColumn* [window->width];
for (int i=0; i<window->width; i++) _columns[i] = new MatrixEffectColumn(window, i);
}
void RandomMatrixEffect::start() {
_columns = new MatrixEffectColumn* [window->width];
for (int i=0; i<window->width; i++) _columns[i] = new RandomMatrixEffectColumn(window, i);
}
void RainbowMatrixEffect::start() {
_columns = new MatrixEffectColumn* [window->width];
for (int i=0; i<window->width; i++) _columns[i] = new RainbowMatrixEffectColumn(window, i);
}
void MatrixEffect::stop() {
for (int i=0; i<window->width; i++) {
delete _columns[i];
}
delete[] _columns;
}
void MatrixEffect::loop() {
window->clear();
for (int i=0; i<window->width; i++) _columns[i].loop();
for (int i=0; i<window->width; i++) _columns[i]->loop();
}