48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include "Animation/StellarAnimation.h"
|
|
|
|
#include <iostream>
|
|
|
|
StellarAnimation::StellarAnimation(Fader *fader,
|
|
const Fader::Color &background_color, const Fader::Color &star_color,
|
|
int fadestep, int spawn_interval_frames)
|
|
: Animation(fader),
|
|
m_backgroundColor(background_color),
|
|
m_starColor(star_color),
|
|
m_fadestep(fadestep),
|
|
m_spawnInterval(spawn_interval_frames)
|
|
{
|
|
reset();
|
|
}
|
|
|
|
void StellarAnimation::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);
|
|
}
|
|
|
|
if(!m_stopping && ((frame % m_spawnInterval) == 0)) {
|
|
// create new pixels
|
|
std::uniform_int_distribution<int> stripRng(0, nstrip-1);
|
|
std::uniform_int_distribution<int> ledRng(0, nled-1);
|
|
|
|
int strip = stripRng(m_gen);
|
|
int led = ledRng(m_gen);
|
|
|
|
m_fader->add_color(strip, led, m_starColor);
|
|
m_fader->fade_color(strip, led, m_backgroundColor);
|
|
}
|
|
|
|
m_fader->update();
|
|
m_running = !m_stopping || m_fader->something_changed();
|
|
}
|
|
|
|
void StellarAnimation::reset(void)
|
|
{
|
|
m_stopping = false;
|
|
m_running = true;
|
|
}
|