59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
|
#pragma once
|
||
|
|
||
|
#include <random>
|
||
|
#include <list>
|
||
|
|
||
|
#include "Animation.h"
|
||
|
|
||
|
#include "fasttrigon.h"
|
||
|
|
||
|
class SnowfallAnimation : public Animation
|
||
|
{
|
||
|
public:
|
||
|
SnowfallAnimation(Fader *fader);
|
||
|
|
||
|
void loop(uint64_t frame) override;
|
||
|
|
||
|
void stop(void) override
|
||
|
{
|
||
|
m_stopping = true;
|
||
|
}
|
||
|
|
||
|
void reset(void) override;
|
||
|
|
||
|
private:
|
||
|
class SnowFlake
|
||
|
{
|
||
|
public:
|
||
|
SnowFlake(Fader *fader, int32_t phase, int32_t vertSpeed, int32_t baseStrip);
|
||
|
|
||
|
void move(void);
|
||
|
bool has_fallen(void) const;
|
||
|
|
||
|
void render(void) const;
|
||
|
|
||
|
int32_t cur_strip(void) const;
|
||
|
|
||
|
private:
|
||
|
Fader *m_fader;
|
||
|
|
||
|
int32_t m_phase;
|
||
|
int32_t m_phaseIncPerFrame;
|
||
|
int32_t m_vertSpeed; // in 1/256 LEDs
|
||
|
|
||
|
int32_t m_radius; // in 1/256 LEDs
|
||
|
int32_t m_radiusSq; // in 1/256 LEDs
|
||
|
|
||
|
int32_t m_basePosStrip; // in 1/256 strips (for speed only)
|
||
|
int32_t m_posStrip; // in 1/256 strips
|
||
|
int32_t m_posLED; // in 1/256 LEDs
|
||
|
};
|
||
|
|
||
|
std::list<SnowFlake> m_snowFlakes;
|
||
|
std::vector<uint32_t> m_snowLevel; // level for each strip in 1/256 LEDs
|
||
|
|
||
|
std::default_random_engine m_gen;
|
||
|
|
||
|
bool m_stopping;
|
||
|
};
|