esp32-sk6812/src/Animation/ChristmasGlitterAnimation.cpp

59 lines
1.7 KiB
C++

#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;
}