Added effect Matrix. Closes #7.
This commit is contained in:
parent
08ac5c891c
commit
678d0dbe8a
69
effects.h
69
effects.h
@ -296,3 +296,72 @@ class MultiDynamic : public SingleDynamic {
|
|||||||
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(random8(), 120, 255);
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -34,7 +34,7 @@ typedef struct {
|
|||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "effects.h"
|
#include "effects.h"
|
||||||
|
|
||||||
#define NUM_EFFECTS 9
|
#define NUM_EFFECTS 10
|
||||||
//EffectEntry effects[NUM_EFFECTS];
|
//EffectEntry effects[NUM_EFFECTS];
|
||||||
Sinematrix3 sinematrix3;
|
Sinematrix3 sinematrix3;
|
||||||
BigClock big_clock;
|
BigClock big_clock;
|
||||||
@ -45,6 +45,7 @@ Animation anim_koopa(&koopa, CRGB(0x000000), 0, 0);
|
|||||||
Animation anim_couple_rain(&couple_rain, CRGB(0x000000), -8, -16);
|
Animation anim_couple_rain(&couple_rain, CRGB(0x000000), -8, -16);
|
||||||
SingleDynamic single_dynamic;
|
SingleDynamic single_dynamic;
|
||||||
MultiDynamic multi_dynamic;
|
MultiDynamic multi_dynamic;
|
||||||
|
MatrixEffect matrix;
|
||||||
|
|
||||||
EffectEntry effects[NUM_EFFECTS] = {
|
EffectEntry effects[NUM_EFFECTS] = {
|
||||||
{"sinematrix3", (Effect *)&sinematrix3},
|
{"sinematrix3", (Effect *)&sinematrix3},
|
||||||
@ -55,7 +56,8 @@ EffectEntry effects[NUM_EFFECTS] = {
|
|||||||
{"koopa", (Effect *)&anim_koopa},
|
{"koopa", (Effect *)&anim_koopa},
|
||||||
{"couple_rain", (Effect *)&anim_couple_rain},
|
{"couple_rain", (Effect *)&anim_couple_rain},
|
||||||
{"single_dynamic", (Effect *)&single_dynamic},
|
{"single_dynamic", (Effect *)&single_dynamic},
|
||||||
{"multi_dynamic", (Effect *)&multi_dynamic}
|
{"multi_dynamic", (Effect *)&multi_dynamic},
|
||||||
|
{"matrix", (Effect *)&matrix},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user