From 994f4894dd0fa06ab49d42b800598a5963eadfda Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 24 Oct 2019 06:33:16 +0200 Subject: [PATCH] effect_lightspeed: New effect. --- include/effect_lightspeed.h | 32 +++++++++++++++++++ include/settings.h | 4 +++ src/effect_lightspeed.cpp | 63 +++++++++++++++++++++++++++++++++++++ src/effects.cpp | 62 ++++++++++++++++++------------------ src/settings.cpp | 4 ++- 5 files changed, 134 insertions(+), 31 deletions(-) create mode 100644 include/effect_lightspeed.h create mode 100644 src/effect_lightspeed.cpp diff --git a/include/effect_lightspeed.h b/include/effect_lightspeed.h new file mode 100644 index 0000000..3e26ed2 --- /dev/null +++ b/include/effect_lightspeed.h @@ -0,0 +1,32 @@ +#pragma once + +#include "Effect.h" +#include "my_fastled.h" + +class LightspeedEffectStar { +private: + uint16_t _angle; + accum88 _start; + uint16_t _speed; + uint16_t _target; + uint8_t _saturation; + void _init(); +public: + LightspeedEffectStar(); + void loop(Window* win); +}; + +class LightspeedEffect : public Effect { +private: + LightspeedEffectStar* _stars; + uint8_t _count; + void _init(); + void _delete(); +public: + LightspeedEffect(); + ~LightspeedEffect(); + void loop(uint16_t ms); + boolean can_be_shown_with_clock(); + String get_name() override { return "lightspeed"; } +}; + diff --git a/include/settings.h b/include/settings.h index 9235069..6da7f56 100644 --- a/include/settings.h +++ b/include/settings.h @@ -74,6 +74,10 @@ struct Settings { uint16_t blend_speed = 10; uint16_t restart_after_steps = 100; } gol; + + struct /* lightspeed */ { + uint16_t count = 25; + } lightspeed; struct /* sines */ { uint16_t count = 5; diff --git a/src/effect_lightspeed.cpp b/src/effect_lightspeed.cpp new file mode 100644 index 0000000..2bdbe84 --- /dev/null +++ b/src/effect_lightspeed.cpp @@ -0,0 +1,63 @@ +#include "effect_lightspeed.h" +#include "config.h" +#include "functions.h" +#include "prototypes.h" + +LightspeedEffect::LightspeedEffect() { + window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + _init(); +} + +LightspeedEffect::~LightspeedEffect() { + delete window; + _delete(); +} + +void LightspeedEffect::_init() { + _count = settings.effects.lightspeed.count; + _stars = new LightspeedEffectStar[_count]; + for (int i=0; i<_count; i++) { + _stars[i] = LightspeedEffectStar(); + } +} + +void LightspeedEffect::_delete() { + delete[] _stars; +} + +void LightspeedEffect::loop(uint16_t ms) { + if (settings.effects.lightspeed.count != _count) { + _delete(); + _init(); + } + window->clear(); + for (int i=0; i<_count; i++) { + _stars[i].loop(window); + } +} + +boolean LightspeedEffect::can_be_shown_with_clock() { return true; }; + +LightspeedEffectStar::LightspeedEffectStar() { + _init(); +} + +void LightspeedEffectStar::_init() { + _angle = random16(); + _start = 0; + _speed = random16(128, 2<<8); + _target = random16(25<<8, 35<<8); + _saturation = random8(20); +} + +void LightspeedEffectStar::loop(Window* win) { + CRGB col = CHSV(192, _saturation, 255); + if (_start < (8<<8)) { + win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _start>>8, &col); + } else { + win->lineWithAngle(win->width/2, win->height/2, _angle, (_start>>8) - 8, 8, &col); + } + _start+=_speed; + //_angle+=8<<8; + if (_start > _target) _init(); +} diff --git a/src/effects.cpp b/src/effects.cpp index b340e85..9039755 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -23,43 +23,45 @@ #include "effect_marquee.h" #include "effect_blur2d.h" #include "effect_tv_static.h" +#include "effect_lightspeed.h" Effect* current_effect; ClockEffect effect_clock; +// We're using 0 instead of false to get a better visual difference between true and false. const EffectEntry effects[] = { - /* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }}, - /* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }}, - /* 2 */ {"clock", false, [](){ return new ClockEffect(); }}, - /* 3 */ {"bell", false, [](){ return new BellEffect(); }}, - /* 4 */ {"off", false, [](){ return new StaticEffect(0x000000); }}, - /* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }}, - /* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }}, - /* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }}, - /* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }}, - /* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }}, - /* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }}, - /* 11 */ {"cycle", false, [](){ return new CycleEffect(); }}, - /* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }}, - /* 13 */ {"confetti", true, [](){ return new ConfettiEffect(); }}, - /* 14 */ {"random_confetti", true, [](){ return new RandomConfettiEffect(); }}, - /* 15 */ {"snake", true, [](){ return new SnakeEffect(); }}, - /* 16 */ {"firework", true, [](){ return new FireworkEffect(); }}, - /* 17 */ {"gol", true, [](){ return new GolEffect(); }}, - /* 18 */ {"pixel_clock", false, [](){ return new PixelClockEffect(); }}, - /* 19 */ {"dvd", false, [](){ return new DvdEffect(); }}, - /* 20 */ {"analog_clock", false, [](){ return new AnalogClockEffect(); }}, - /* 21 */ {"sines", true, [](){ return new SinesEffect(); }}, - /* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }}, - /* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }}, - /* 24 */ {"night_clock", false, [](){ return new NightClockEffect(); }}, - /* 25 */ {"tv_static", false, [](){ return new TvStaticEffect(); }}, - /* 26 */ {"sinematrix3_rainbow", true,[](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }}, - /* 27 */ {"sinematrix3_purplefly", true,[](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }}, - + /* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }}, + /* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }}, + /* 2 */ {"clock", 0, [](){ return new ClockEffect(); }}, + /* 3 */ {"bell", 0, [](){ return new BellEffect(); }}, + /* 4 */ {"off", 0, [](){ return new StaticEffect(0x000000); }}, + /* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }}, + /* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }}, + /* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }}, + /* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }}, + /* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }}, + /* 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(); }}, + /* 15 */ {"snake", true, [](){ return new SnakeEffect(); }}, + /* 16 */ {"firework", true, [](){ return new FireworkEffect(); }}, + /* 17 */ {"gol", true, [](){ return new GolEffect(); }}, + /* 18 */ {"pixel_clock", 0, [](){ return new PixelClockEffect(); }}, + /* 19 */ {"dvd", 0, [](){ return new DvdEffect(); }}, + /* 20 */ {"analog_clock", 0, [](){ return new AnalogClockEffect(); }}, + /* 21 */ {"sines", true, [](){ return new SinesEffect(); }}, + /* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }}, + /* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }}, + /* 24 */ {"night_clock", 0, [](){ return new NightClockEffect(); }}, + /* 25 */ {"tv_static", 0, [](){ return new TvStaticEffect(); }}, + /* 26 */ {"sinematrix3_rainbow", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }}, + /* 27 */ {"sinematrix3_purplefly", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }}, + /* 28 */ {"lightspeed", true, [](){ return new LightspeedEffect(); }}, }; -const uint8_t effects_size = 28; +const uint8_t effects_size = 29; Effect* select_effect(const char* name) { diff --git a/src/settings.cpp b/src/settings.cpp index 7885a8c..98c8664 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -36,6 +36,8 @@ Setting all_settings[] = { {"effects.gol.start_percentage", &settings.effects.gol.start_percentage, TYPE_UINT8}, {"effects.gol.blend_speed", &settings.effects.gol.blend_speed, TYPE_UINT8}, {"effects.gol.restart_after_steps", &settings.effects.gol.restart_after_steps, TYPE_UINT8}, + + {"effects.lightspeed.count", &settings.effects.lightspeed.count, TYPE_UINT8}, {"effects.matrix.length_min", &settings.effects.matrix.length_min, TYPE_UINT8}, {"effects.matrix.length_max", &settings.effects.matrix.length_max, TYPE_UINT8}, @@ -51,7 +53,7 @@ Setting all_settings[] = { {"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16}, }; -const uint8_t all_settings_size = 31; +const uint8_t all_settings_size = 32; bool change_setting(const char* key, uint16_t new_value) { LOGln("Settings * Setting %s to new value %d.", key, new_value);