animations: implement a rain animation for weather
This commit is contained in:
48
src/animations/Rain.h
Normal file
48
src/animations/Rain.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <Figments.h>
|
||||
|
||||
class RainAnimation: public Figment {
|
||||
private:
|
||||
struct Raindrop {
|
||||
int size = 20;
|
||||
int x = random(255);
|
||||
int y = random(255);
|
||||
CHSV fg{180, 255, 255};
|
||||
CHSV nextColor{180, 255, 255};
|
||||
|
||||
void render(Display* dpy) const {
|
||||
Surface sfc{dpy, {x - size, y - size}, {x + size, y + size}};
|
||||
paint(sfc);
|
||||
}
|
||||
|
||||
void paint(Surface& sfc) const {
|
||||
sfc.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
int distance = 255 - (min(128, abs(128 - surfaceCoords.x)) + min(128, abs(128 - surfaceCoords.y)));
|
||||
pixel += CHSV{fg.h, fg.s, scale8_video(fg.v, distance)};
|
||||
});
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (random(255) >= 100) {
|
||||
y++;
|
||||
if (y >= 255) {
|
||||
y = 0;
|
||||
x += 13;
|
||||
x %= 255;
|
||||
fg = nextColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SpriteList<Raindrop, 10> m_drops;
|
||||
uint16_t m_noiseOffset;
|
||||
CHSV m_curColor{180, 255, 255};
|
||||
AnimatedNumber m_hue;
|
||||
public:
|
||||
RainAnimation();
|
||||
//void handleEvent(const InputEvent& evt) override;
|
||||
void loop() override;
|
||||
void render(Display* dpy) const override;
|
||||
void handleEvent(const InputEvent& evt) override;
|
||||
};
|
||||
Reference in New Issue
Block a user