Added „Christmas Glitter“ animation
This commit is contained in:
parent
52053ea3bb
commit
3671ecc635
|
@ -10,3 +10,4 @@
|
|||
#include "RgbwSinusAnimation.h"
|
||||
#include "SnowfallAnimation.h"
|
||||
#include "StellarAnimation.h"
|
||||
#include "ChristmasGlitterAnimation.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);
|
||||
|
|
36
include/Animation/ChristmasGlitterAnimation.h
Normal file
36
include/Animation/ChristmasGlitterAnimation.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <random>
|
||||
#include <list>
|
||||
|
||||
#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;
|
||||
};
|
|
@ -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
|
||||
}
|
||||
|
|
58
src/Animation/ChristmasGlitterAnimation.cpp
Normal file
58
src/Animation/ChristmasGlitterAnimation.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "Animation/ChristmasGlitterAnimation.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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<int> stripRng(0, nstrip-1);
|
||||
std::uniform_int_distribution<int> 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;
|
||||
}
|
Loading…
Reference in a new issue