#include "SolidAnimation.h" #include "../Static.h" SolidAnimation::SolidAnimation() : Figment("Solid") { } void SolidAnimation::randomize() { m_isRandom = true; m_blobs.forEach([](Blob& blob) { blob.setPos(random(140)); blob.setBrightness(random(255)); if (random(254) % 2) { blob.setVelocity(-1); } }); } void SolidAnimation::handleEvent(const InputEvent& evt) { if (evt.intent == InputEvent::SetColor) { CRGB nextColor = evt.asRGB(); m_red.set(nextColor.red); m_green.set(nextColor.green); m_blue.set(nextColor.blue); m_changePct.set(0, 255); m_prevColor = m_curColor; m_curColor = nextColor; m_horizontal = !m_horizontal; } else if (evt.intent == InputEvent::Beat) { //m_isRandom = false; } } void SolidAnimation::loop() { if (!m_isRandom) { randomize(); } EVERY_N_MILLIS(20) { m_changePct.update(1); m_red.update(1); m_green.update(1); m_blue.update(1); CRGB rgb{m_red, m_green, m_blue}; CHSV hsv = rgb2hsv_approximate(rgb); m_blobs.forEach([=](Blob& blob) { blob.setHue(hsv.hue); blob.setSaturation(hsv.saturation); }); m_blobs.update(); } } #include void SolidAnimation::render(Display* dpy) const { PerfCounter _("solidRender"); CRGB color(m_red.value(), m_green.value(), m_blue.value()); CRGB scaledPrev = m_prevColor; scaledPrev = color.nscale8(30); uint8_t frame = ease8InOutApprox(m_changePct); if (F_LIKELY(frame == 255)) { Surface(dpy, {0, 0}, {255, 255}) = color.nscale8(10); } else { uint8_t cutoff = (frame / 2); uint8_t rotation = m_horizontal ? 0 : 128; Surface(dpy, {0, 0}, {128 - cutoff, 255}, rotation) = scaledPrev; Surface(dpy, {128 - cutoff, 0}, {128 + cutoff, 255}, rotation) = scaledPrev; Surface(dpy, {128 + cutoff, 0}, {255, 255}, rotation) = scaledPrev; } m_blobs.render(dpy); } STATIC_ALLOC(SolidAnimation); STATIC_TASK(SolidAnimation);