2019-05-29 22:49:54 +00:00
|
|
|
#include "effect_matrix.h"
|
2019-06-04 03:55:24 +00:00
|
|
|
#include "my_color_palettes.h"
|
2019-05-29 22:49:54 +00:00
|
|
|
#include "functions.h"
|
|
|
|
|
2019-06-04 03:55:24 +00:00
|
|
|
MatrixEffectColumn::MatrixEffectColumn() {
|
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
|
2019-06-04 03:55:24 +00:00
|
|
|
MatrixEffectColumn::MatrixEffectColumn(Window* win, int xPos) : MatrixEffectColumn() {
|
2019-06-07 04:24:16 +00:00
|
|
|
window = win;
|
|
|
|
x = xPos;
|
|
|
|
start();
|
2019-06-11 17:48:09 +00:00
|
|
|
y = random8(0, window->height);
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::start() {
|
2019-06-07 04:24:16 +00:00
|
|
|
y=-1;
|
|
|
|
length = random8(EFFECT_MATRIX_LENGTH_MIN, EFFECT_MATRIX_LENGTH_MAX);
|
|
|
|
running = true;
|
|
|
|
speed = random8(EFFECT_MATRIX_SPEED_MIN, EFFECT_MATRIX_SPEED_MAX);
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::advance() {
|
2019-06-07 04:24:16 +00:00
|
|
|
y++;
|
2019-06-11 17:48:09 +00:00
|
|
|
if (y-length > window->height) running = false;
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::draw() {
|
2019-06-07 04:24:16 +00:00
|
|
|
for(int i=0; i<length; i++) {
|
2019-06-16 10:43:05 +00:00
|
|
|
CRGB color = _getColor(i);
|
2019-06-11 17:48:09 +00:00
|
|
|
window->setPixel(x, y-i, &color);
|
2019-06-04 04:51:36 +00:00
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::loop() {
|
2019-06-07 04:24:16 +00:00
|
|
|
if (!running) {
|
|
|
|
if (random8() < 20) {
|
|
|
|
// Start the column again.
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (millis() - last_move > speed) {
|
|
|
|
advance();
|
|
|
|
last_move = millis();
|
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
|
2019-06-07 04:24:16 +00:00
|
|
|
draw();
|
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-16 10:43:05 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-29 22:49:54 +00:00
|
|
|
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
|
|
|
|
|
|
|
|
MatrixEffect::MatrixEffect() {
|
2019-06-15 12:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffect::start() {
|
2019-06-16 10:43:05 +00:00
|
|
|
_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);
|
2019-06-15 12:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffect::stop() {
|
2019-06-16 10:43:05 +00:00
|
|
|
for (int i=0; i<window->width; i++) {
|
|
|
|
delete _columns[i];
|
|
|
|
}
|
2019-06-15 12:17:06 +00:00
|
|
|
delete[] _columns;
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffect::loop() {
|
2019-06-11 17:48:09 +00:00
|
|
|
window->clear();
|
2019-06-16 10:43:05 +00:00
|
|
|
for (int i=0; i<window->width; i++) _columns[i]->loop();
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|