diff --git a/include/SimpleEffect.h b/include/SimpleEffect.h new file mode 100644 index 0000000..e3b6315 --- /dev/null +++ b/include/SimpleEffect.h @@ -0,0 +1,23 @@ +#pragma once +#include "Effect.h" +#include "prototypes.h" + +class SimpleEffect : public Effect { +protected: + Window* window = &Window::window_full; // Use a full screen window per default. + boolean _fade_out = false; + boolean _random_colors = false; + boolean _cycle_color = true; + uint8_t _color = 0; + String _name; + simple_effect_t _method; +public: + SimpleEffect(String name, simple_effect_t method): _name { name }, _method { method } {}; + SimpleEffect* with_fadeout() { _fade_out=true; return this;} + SimpleEffect* with_random_colors() { _random_colors=true; return this;} + SimpleEffect* with_static_color(uint8_t color) { _cycle_color=false; _color=color; return this; } + void loop(uint16_t ms) override; + String get_name() { return _name; }; + boolean can_be_shown_with_clock() { return true; } + +}; \ No newline at end of file diff --git a/include/effect_confetti.h b/include/effect_confetti.h deleted file mode 100644 index 604d7f3..0000000 --- a/include/effect_confetti.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Effect.h" -#include "my_fastled.h" - -class ConfettiEffect : public Effect { -protected: - virtual CRGB _getColor(); -public: - void loop(uint16_t ms); - boolean can_be_shown_with_clock(); - String get_name() override { return "confetti"; } -}; - -class RandomConfettiEffect : public ConfettiEffect { -protected: - CRGB _getColor() override; - String get_name() override { return "random_confetti"; } -}; - diff --git a/include/prototypes.h b/include/prototypes.h index 9788871..4327e99 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -1,6 +1,7 @@ #pragma once #include +#include "my_fastled.h" extern uint8_t baseHue; extern char hostname[30]; @@ -31,3 +32,5 @@ typedef struct { uint16_t x; uint16_t y; } Coords; + +typedef std::function simple_effect_t; \ No newline at end of file diff --git a/src/SimpleEffect.cpp b/src/SimpleEffect.cpp new file mode 100644 index 0000000..2193f2f --- /dev/null +++ b/src/SimpleEffect.cpp @@ -0,0 +1,23 @@ +#include "SimpleEffect.h" + +void SimpleEffect::loop(uint16_t ms) { + if (_fade_out) window->fadeToBlackBy(3); + accum88 t = millis() * 0x100 / 1000; + for(uint8_t x=0; xwidth; x++) for(uint8_t y=0; yheight; y++) { + uint16_t i = y*window->width + x; + int8_t r = _method(t, i, x, y); + + if (_fade_out && r==0) { + continue; + } + + CRGB color; + if (_random_colors) { + color = CHSV(random8(), 255, abs(r)*2); + } else { + color = CHSV(_cycle_color ? baseHue : _color, r<0?0:255, abs(r)*2); + } + + window->setPixel(x, y, &color); + } +} \ No newline at end of file diff --git a/src/effect_confetti.cpp b/src/effect_confetti.cpp deleted file mode 100644 index 3caccf6..0000000 --- a/src/effect_confetti.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "effect_confetti.h" -#include "config.h" -#include "functions.h" -#include "prototypes.h" - -void ConfettiEffect::loop(uint16_t ms) { - window->fadeToBlackBy(3); - for (int i=0; iaddPixelColor(random16(LED_COUNT), &color); - } -} - -CRGB ConfettiEffect::_getColor() { - return CHSV(baseHue + random8(64), 255, 255); -} - -CRGB RandomConfettiEffect::_getColor() { - return CHSV(random8(), 255, 255); -} - -boolean ConfettiEffect::can_be_shown_with_clock() { return true; }; diff --git a/src/effects.cpp b/src/effects.cpp index e0221b8..0f911fa 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -11,7 +11,6 @@ #include "effect_matrix.h" #include "effect_twirl.h" #include "effect_cycle.h" -#include "effect_confetti.h" #include "effect_snake.h" #include "effect_fire.h" #include "effect_firework.h" @@ -26,6 +25,7 @@ #include "effect_lightspeed.h" #include "effect_diamond.h" #include "effect_tpm2_net.h" +#include "SimpleEffect.h" Effect* current_effect; @@ -47,8 +47,8 @@ EffectEntry effects[] = { /* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }}, /* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }}, /* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }}, - /* 13 */ {"confetti", true, [](){ return new ConfettiEffect(); }}, - /* 14 */ {"random_confetti", true, [](){ return new RandomConfettiEffect(); }}, + /* 13 */ {"confetti", true, [](){ return (new SimpleEffect("confetti", [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t{return random8()>252 ? 127 : 0;}))->with_fadeout();}}, + /* 14 */ {"rainbow_confetti", true, [](){ return (new SimpleEffect("rainbow_confetti", [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t{return random8()>252 ? 127 : 0;}))->with_fadeout()->with_random_colors();}}, /* 15 */ {"snake", true, [](){ return new SnakeEffect(); }}, /* 16 */ {"firework", true, [](){ return new FireworkEffect(); }}, /* 17 */ {"gol", true, [](){ return new GolEffect(); }}, @@ -68,8 +68,9 @@ EffectEntry effects[] = { /* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }}, /* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }}, /* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }}, + /* 34 */ {"slow_blinking", true, [](){ return new SimpleEffect("slow_blinking", [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t{return sin8((t>>3) + ((((x+1)*(y+1)*i*15) >> 2) & 0xFF))-128;});}}, }; -const uint8_t effects_size = 34; +const uint8_t effects_size = 35; Effect* select_effect(const char* name) {