2022-06-11 09:02:27 +00:00
|
|
|
#include "SolidAnimation.h"
|
|
|
|
#include "../Static.h"
|
2019-05-10 05:17:29 +00:00
|
|
|
|
2023-02-18 15:33:09 +00:00
|
|
|
SolidAnimation::SolidAnimation() : Figment("Solid") {
|
2022-06-11 09:02:27 +00:00
|
|
|
}
|
2019-05-10 05:17:29 +00:00
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
void SolidAnimation::randomize() {
|
|
|
|
m_isRandom = true;
|
|
|
|
m_blobs.forEach([](Blob& blob) {
|
|
|
|
blob.setPos(random(140));
|
|
|
|
blob.setBrightness(random(255));
|
2023-02-20 06:09:01 +00:00
|
|
|
if (random(254) % 2) {
|
2022-06-11 09:02:27 +00:00
|
|
|
blob.setVelocity(-1);
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
2022-06-11 09:02:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2023-02-20 06:09:01 +00:00
|
|
|
//m_isRandom = false;
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
2022-06-11 09:02:27 +00:00
|
|
|
}
|
2019-05-10 05:17:29 +00:00
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
void SolidAnimation::loop() {
|
|
|
|
if (!m_isRandom) {
|
|
|
|
randomize();
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
2023-02-20 06:09:01 +00:00
|
|
|
EVERY_N_MILLIS(20) {
|
|
|
|
m_changePct.update(1);
|
|
|
|
m_red.update(1);
|
|
|
|
m_green.update(1);
|
|
|
|
m_blue.update(1);
|
2022-06-11 09:02:27 +00:00
|
|
|
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 <Perfcounter.h>
|
2019-05-10 05:17:29 +00:00
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
void SolidAnimation::render(Display* dpy) const {
|
|
|
|
PerfCounter _("solidRender");
|
|
|
|
CRGB color(m_red.value(), m_green.value(), m_blue.value());
|
2023-02-20 06:09:01 +00:00
|
|
|
CRGB scaledPrev = m_prevColor;
|
|
|
|
scaledPrev = color.nscale8(30);
|
2022-06-11 09:02:27 +00:00
|
|
|
uint8_t frame = ease8InOutApprox(m_changePct);
|
2023-02-20 06:09:01 +00:00
|
|
|
if (F_LIKELY(frame == 255)) {
|
|
|
|
Surface(dpy, {0, 0}, {255, 255}) = color.nscale8(10);
|
2022-06-11 09:02:27 +00:00
|
|
|
} else {
|
|
|
|
uint8_t cutoff = (frame / 2);
|
|
|
|
uint8_t rotation = m_horizontal ? 0 : 128;
|
2023-02-20 06:09:01 +00:00
|
|
|
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;
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
2022-06-11 09:02:27 +00:00
|
|
|
m_blobs.render(dpy);
|
|
|
|
}
|
|
|
|
STATIC_ALLOC(SolidAnimation);
|
|
|
|
STATIC_TASK(SolidAnimation);
|