49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include "Animation/ConnectionEstablishedAnimation.h"
|
|
|
|
ConnectionEstablishedAnimation::ConnectionEstablishedAnimation(Fader *fader, bool connected)
|
|
: Animation(fader), m_connected(connected)
|
|
{}
|
|
|
|
void ConnectionEstablishedAnimation::loop(uint64_t frame)
|
|
{
|
|
std::size_t nled = m_fader->modules_per_strip();
|
|
std::size_t nstrip = m_fader->strips();
|
|
uint8_t intensity = 0;
|
|
|
|
std::uniform_int_distribution<uint8_t> flareVariation(0, 31);
|
|
|
|
if(frame == 0) {
|
|
m_fader->set_fadestep(1);
|
|
m_fader->fade_color(Fader::Color{0, 0, 0, 0});
|
|
}
|
|
|
|
std::size_t led = frame/3;
|
|
|
|
if(led < nled) {
|
|
if((frame % 3) == 0) {
|
|
for(std::size_t strip = 0; strip < nstrip; strip++) {
|
|
intensity = 48 + flareVariation(m_gen);
|
|
|
|
Fader::Color c;
|
|
if(m_connected) {
|
|
c.g = intensity * led / nled;
|
|
} else {
|
|
c.r = intensity * led / nled;
|
|
}
|
|
|
|
c.b = (intensity - intensity * led / nled) / 2;
|
|
|
|
m_fader->set_color(strip, led, c);
|
|
m_fader->fade_color(strip, led, Fader::Color{0,0,0,0});
|
|
}
|
|
}
|
|
}
|
|
|
|
m_fader->update();
|
|
|
|
if(led >= nled) {
|
|
// stop the animation if everything is dark
|
|
m_running = m_fader->something_changed();
|
|
}
|
|
}
|