pitrix/src/effect_matrix.cpp

73 lines
1.6 KiB
C++
Raw Normal View History

#include "effect_matrix.h"
#include "my_color_palettes.h"
#include "functions.h"
MatrixEffectColumn::MatrixEffectColumn() {
}
MatrixEffectColumn::MatrixEffectColumn(Window* win, int xPos) : MatrixEffectColumn() {
2019-06-07 04:24:16 +00:00
window = win;
x = xPos;
start();
y = random8(0, window->height);
}
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);
}
void MatrixEffectColumn::advance() {
2019-06-07 04:24:16 +00:00
y++;
if (y-length > window->height) running = false;
}
void MatrixEffectColumn::draw() {
2019-06-07 04:24:16 +00:00
for(int i=0; i<length; i++) {
CRGB color;
2019-06-07 04:24:16 +00:00
if (i==0) {
color = CRGB(255, 255, 255);
2019-06-07 04:24:16 +00:00
} else {
color = ColorFromPalette((CRGBPalette16)palette_matrix, 255 * (length - i) / length);
2019-06-07 04:24:16 +00:00
}
window->setPixel(x, y-i, &color);
}
}
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-06-07 04:24:16 +00:00
draw();
}
}
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);
}
void MatrixEffect::stop() {
delete[] _columns;
}
void MatrixEffect::loop() {
window->clear();
for (int i=0; i<window->width; i++) _columns[i].loop();
}