esp32-sk6812/include/Animation/FireworkAnimation.h

65 lines
1.3 KiB
C++

#pragma once
#include <random>
#include <list>
#include <array>
#include "Animation.h"
class FireworkRocket
{
private:
enum LaunchPhase {
PHASE_RISING,
PHASE_SPREADING,
PHASE_DONE
};
std::array<int, 6> m_flareXPos;
std::array<int, 6> m_flareYPos;
LaunchPhase m_phase;
int m_rocketXPos;
int m_rocketYPos;
int m_targetHeight;
int m_riseSpeed;
uint64_t m_spreadStartFrame;
Fader::Color m_color;
public:
FireworkRocket(int start_x, int target_height, int rise_speed, const Fader::Color &color);
void move(uint64_t frame);
void render(Fader *fader);
bool done(void) const { return m_phase == PHASE_DONE; }
};
class FireworkAnimation : public Animation
{
public:
FireworkAnimation(Fader *fader, int vspeed = 128, int spawn_rate = 8);
void loop(uint64_t frame) override;
void stop(void) override
{
m_stopping = true;
}
void reset(void) override;
private:
std::default_random_engine m_gen;
std::list<FireworkRocket> m_rockets;
int m_vspeed;
int m_spawnRate; // average pixels per second
bool m_stopping;
};