From bbc01f7cea6ed2e5996a49d46694d5062fe7dd74 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Mon, 20 Feb 2023 07:09:01 +0100 Subject: [PATCH] animations: solid: increase pre-blob color headroom, make color transitions much smoother --- src/animations/SolidAnimation.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/animations/SolidAnimation.cpp b/src/animations/SolidAnimation.cpp index 8de1289..c0077de 100644 --- a/src/animations/SolidAnimation.cpp +++ b/src/animations/SolidAnimation.cpp @@ -9,7 +9,7 @@ void SolidAnimation::randomize() { m_blobs.forEach([](Blob& blob) { blob.setPos(random(140)); blob.setBrightness(random(255)); - if (random(255) % 2) { + if (random(254) % 2) { blob.setVelocity(-1); } }); @@ -26,7 +26,7 @@ void SolidAnimation::handleEvent(const InputEvent& evt) { m_curColor = nextColor; m_horizontal = !m_horizontal; } else if (evt.intent == InputEvent::Beat) { - m_isRandom = false; + //m_isRandom = false; } } @@ -34,13 +34,11 @@ void SolidAnimation::loop() { if (!m_isRandom) { randomize(); } - m_red.update(15); - m_green.update(15); - m_blue.update(15); - EVERY_N_MILLIS(16) { - m_changePct.update(12); - } - EVERY_N_MILLIS(6) { + 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) { @@ -56,15 +54,17 @@ void SolidAnimation::loop() { 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 (frame == 255) { - Surface(dpy, {0, 0}, {255, 255}) = color; + 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) = m_prevColor; - Surface(dpy, {128 - cutoff, 0}, {128 + cutoff, 255}, rotation) = color; - Surface(dpy, {128 + cutoff, 0}, {255, 255}, rotation) = m_prevColor; + 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); }