Added effect Matrix. Closes #7.

This commit is contained in:
2019-05-24 06:25:22 +02:00
parent 08ac5c891c
commit 678d0dbe8a
2 changed files with 73 additions and 2 deletions

View File

@ -296,3 +296,72 @@ class MultiDynamic : public SingleDynamic {
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(random8(), 120, 255);
}
};
class MatrixColumn {
private:
int x, y;
int length;
Window* window;
int speed;
boolean running;
long last_move = 0;
public:
MatrixColumn() {}
MatrixColumn(Window* win, int xPos) {
window = win;
x = xPos;
running = false;
}
void start() {
y=-1;
length = random8()%16+4;
running = true;
speed = random8()/3 + 50;
}
void advance() {
y++;
if (y-length > window->h) running = false;
}
void draw() {
for(int i=0; i<length; i++) {
CRGB color;
if (i==0) color=CHSV(85, 0, 192);
else color=CHSV(85, 255, 255/(length-1)*(length-i));
setPixel(*window, x, y-i, color);
}
}
void loop() {
if (!running) {
if (random8() < 50) {
// Start the column again.
start();
}
} else {
if (millis() - last_move > speed) {
advance();
last_move = millis();
}
draw();
}
}
};
class MatrixEffect : public Effect {
private:
MatrixColumn columns[LED_WIDTH];
public:
boolean can_be_shown_with_clock() { return true; };
MatrixEffect() {
for (int i=0; i<LED_WIDTH; i++) columns[i]=MatrixColumn(&window, i);
}
void loop() {
clear(window);
for (int i=0; i<LED_WIDTH; i++) columns[i].loop();
}
};