animations: implement a rain animation for weather
This commit is contained in:
45
src/animations/Rain.cpp
Normal file
45
src/animations/Rain.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "Rain.h"
|
||||
#include "../Static.h"
|
||||
|
||||
RainAnimation::RainAnimation() : Figment("Rain")
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RainAnimation::render(Display* dpy) const
|
||||
{
|
||||
Surface sfc = Surface(dpy, {0, 0}, {255, 255});
|
||||
uint8_t noiseY = sin8(m_noiseOffset % 255);
|
||||
uint8_t noiseX = cos8(m_noiseOffset % 255);
|
||||
sfc.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
pixel = CHSV(m_hue, inoise8(noiseX + coords.x, coords.y), inoise8(m_noiseOffset + coords.x, noiseY + coords.y));
|
||||
});
|
||||
m_drops.render(dpy);
|
||||
}
|
||||
|
||||
void
|
||||
RainAnimation::loop()
|
||||
{
|
||||
EVERY_N_MILLISECONDS(250) {
|
||||
m_drops.update();
|
||||
}
|
||||
EVERY_N_MILLISECONDS(60) {
|
||||
m_hue.update(1);
|
||||
m_curColor.h = m_hue;
|
||||
}
|
||||
m_noiseOffset += 1;
|
||||
}
|
||||
|
||||
void
|
||||
RainAnimation::handleEvent(const InputEvent& evt) {
|
||||
if (evt.intent == InputEvent::SetColor) {
|
||||
CHSV next = rgb2hsv_approximate(evt.asRGB());
|
||||
m_hue.set(next.h);
|
||||
m_drops.forEach([=](Raindrop& drop) {
|
||||
drop.nextColor = next;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_ALLOC(RainAnimation);
|
||||
STATIC_TASK(RainAnimation);
|
||||
Reference in New Issue
Block a user