SingleDynamic and MultiDynamic: Now with fading between the frames, better timing and a bit more saturation.

This commit is contained in:
Fabian Schlenz 2019-05-26 00:30:47 +02:00
parent 7bcb911fec
commit 21c0f1fdf7

View File

@ -272,29 +272,39 @@ class SingleDynamic : public Effect {
protected: protected:
static const int factor = 2; static const int factor = 2;
static const int tile_count = LED_WIDTH/factor * LED_HEIGHT/factor; static const int tile_count = LED_WIDTH/factor * LED_HEIGHT/factor;
virtual int getLoopTime() { return 200; }
CRGB tiles[tile_count]; CRGB tiles[tile_count];
CRGB old_tiles[tile_count];
uint8_t blend = 0;
public: public:
SingleDynamic() { 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(), 180, 255);
} }
virtual void update() { virtual void update() {
tiles[random8() % tile_count] = CHSV(random8(), 120, 255); tiles[random8() % tile_count] = CHSV(random8(), 180, 255);
} }
boolean can_be_shown_with_clock() { return true; } boolean can_be_shown_with_clock() { return true; }
void loop() { virtual void loop() {
EVERY_N_MILLISECONDS(400) { update(); } EVERY_N_MILLISECONDS(getLoopTime()) {
memcpy(old_tiles, tiles, tile_count*sizeof(CRGB));
blend = 0;
update();
}
for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) { for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) {
int index = y/2 * window.w/2 + x/2; int index = y/2 * window.w/2 + x/2;
setPixel(window, x, y, tiles[index]); setPixel(window, x, y, nblend(old_tiles[index], tiles[index], blend));
} }
if (blend < 255) blend+=20;
} }
}; };
class MultiDynamic : public SingleDynamic { class MultiDynamic : public SingleDynamic {
protected:
virtual int getLoopTime() { return 1400; }
public: public:
void update() { void update() {
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(), 180, 255);
} }
}; };