diff --git a/include/Animation/AllAnimations.h b/include/Animation/AllAnimations.h index 1176eeb..f99e76e 100644 --- a/include/Animation/AllAnimations.h +++ b/include/Animation/AllAnimations.h @@ -10,3 +10,4 @@ #include "RgbwSinusAnimation.h" #include "SnowfallAnimation.h" #include "StellarAnimation.h" +#include "ChristmasGlitterAnimation.h" diff --git a/include/Animation/AnimationController.h b/include/Animation/AnimationController.h index 943d4f2..6818ede 100644 --- a/include/Animation/AnimationController.h +++ b/include/Animation/AnimationController.h @@ -20,6 +20,7 @@ class AnimationController FIREWORK = 5, STELLAR = 6, RGBW_SINUS = 7, + CHRISTMAS_GLITTER = 8, NUM_DEFAULT_ANIMATIONS }; @@ -38,7 +39,8 @@ class AnimationController "Matrix Code", "Fireworks", "Twinkling Sky", - "RGBW Sinus" + "RGBW Sinus", + "Christmas Glitter" }; AnimationController(Fader *fader); diff --git a/include/Animation/ChristmasGlitterAnimation.h b/include/Animation/ChristmasGlitterAnimation.h new file mode 100644 index 0000000..912cd3b --- /dev/null +++ b/include/Animation/ChristmasGlitterAnimation.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include + +#include "Animation.h" + +class ChristmasGlitterAnimation : public Animation +{ + public: + ChristmasGlitterAnimation(Fader *fader, + const Fader::Color &background_color = Fader::Color{0x06, 0x04, 0x00, 0x04}, + const Fader::Color &glitter_color = Fader::Color{0x60, 0x40, 0x00, 0x60}, + int fadestep = 1, int background_spawns_per_frame = 20, int spawn_interval_frames = 4); + + void loop(uint64_t frame) override; + + void stop(void) override + { + m_stopping = true; + } + + void reset(void) override; + + private: + std::default_random_engine m_gen; + + Fader::Color m_backgroundColor; + Fader::Color m_glitterColor; + + int m_fadestep; + int m_spawnInterval; // in frames + int m_backgroundSpawnsPerFrame; + + bool m_stopping; +}; diff --git a/src/Animation/AnimationController.cpp b/src/Animation/AnimationController.cpp index 16643d6..aa04810 100644 --- a/src/Animation/AnimationController.cpp +++ b/src/Animation/AnimationController.cpp @@ -78,6 +78,10 @@ void AnimationController::changeAnimation(AnimationController::DefaultAnimation anim.reset(new RgbwSinusAnimation(m_fader)); break; + case CHRISTMAS_GLITTER: + anim.reset(new ChristmasGlitterAnimation(m_fader)); + break; + default: return; // unknown id, do nothing } diff --git a/src/Animation/ChristmasGlitterAnimation.cpp b/src/Animation/ChristmasGlitterAnimation.cpp new file mode 100644 index 0000000..fa3e556 --- /dev/null +++ b/src/Animation/ChristmasGlitterAnimation.cpp @@ -0,0 +1,58 @@ +#include "Animation/ChristmasGlitterAnimation.h" + +#include + +ChristmasGlitterAnimation::ChristmasGlitterAnimation(Fader *fader, + const Fader::Color &background_color, const Fader::Color &glitter_color, + int fadestep, int background_spawns_per_frame, int spawn_interval_frames) + : Animation(fader), + m_backgroundColor(background_color), + m_glitterColor(glitter_color), + m_fadestep(fadestep), + m_spawnInterval(spawn_interval_frames), + m_backgroundSpawnsPerFrame(background_spawns_per_frame) +{ + reset(); +} + +void ChristmasGlitterAnimation::loop(uint64_t frame) +{ + int nled = m_fader->modules_per_strip(); + int nstrip = m_fader->strips(); + + if(frame == 0) { + m_fader->set_fadestep(m_fadestep); + m_fader->fade_color(m_backgroundColor); + } + + // create new pixels + std::uniform_int_distribution stripRng(0, nstrip-1); + std::uniform_int_distribution ledRng(0, nled-1); + + if(!m_stopping) { + if((frame % m_spawnInterval) == 0) { + int strip = stripRng(m_gen); + int led = ledRng(m_gen); + + m_fader->add_color(strip, led, m_glitterColor); + m_fader->fade_color(strip, led, Fader::Color{0x10,0x06,0,0x03}); + } + + for(size_t i = 0; i < m_backgroundSpawnsPerFrame; i++) { + int strip = stripRng(m_gen); + int led = ledRng(m_gen); + + m_fader->add_color(strip, led, m_backgroundColor); + m_fader->fade_color(strip, led, Fader::Color{0x10,0x06,0,0x03}); + } + } + + m_fader->update(); + m_running = !m_stopping || m_fader->something_changed(); +} + +void ChristmasGlitterAnimation::reset(void) +{ + m_stopping = false; + m_running = true; +}