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-05-29 22:49:54 +00:00
|
|
|
window = win;
|
|
|
|
x = xPos;
|
|
|
|
start();
|
|
|
|
y = random8(0, win->h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::start() {
|
|
|
|
y=-1;
|
|
|
|
length = random8(EFFECT_MATRIX_LENGTH_MIN, EFFECT_MATRIX_LENGTH_MAX);
|
|
|
|
running = true;
|
|
|
|
speed = random8(EFFECT_MATRIX_SPEED_MIN, EFFECT_MATRIX_SPEED_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::advance() {
|
|
|
|
y++;
|
|
|
|
if (y-length > window->h) running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::draw() {
|
|
|
|
for(int i=0; i<length; i++) {
|
2019-06-04 03:55:24 +00:00
|
|
|
setPixel(*window, x, y-i, ColorFromPalette((CRGBPalette16)palette_matrix, 255 * (length - i) / length));
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffectColumn::loop() {
|
|
|
|
if (!running) {
|
|
|
|
if (random8() < 20) {
|
|
|
|
// Start the column again.
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (millis() - last_move > speed) {
|
|
|
|
advance();
|
|
|
|
last_move = millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
|
|
|
|
|
|
|
|
MatrixEffect::MatrixEffect() {
|
|
|
|
for (int i=0; i<LED_WIDTH; i++) columns[i] = MatrixEffectColumn(&window, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatrixEffect::loop() {
|
|
|
|
clear(window);
|
|
|
|
for (int i=0; i<LED_WIDTH; i++) columns[i].loop();
|
|
|
|
}
|