FastLED 3.9.15
Loading...
Searching...
No Matches
particles.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/vector.h"
4#include "fl/stl/span.h"
5#include "fl/fx/fx1d.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9
11
52class Particles1d : public Fx1d {
53 public:
57 Particles1d(u16 num_leds, u8 max_particles = 10, u8 fade_rate = 2);
58
60
63 void draw(DrawContext context) override;
64
74
77 void setLifetime(u16 lifetime_ms);
78
81 void setOverdrawCount(u8 count);
82
85 void setSpeed(float speed);
86
89 void setFadeRate(u8 fade_rate);
90
93 void setCyclical(bool cyclical);
94
95 fl::string fxName() const override;
96
97 private:
102 struct Particle {
103 float pos;
104 float baseVel;
108 bool active;
109
111
113 float getPower(u32 now) const;
114
116 void spawn(u16 numLeds);
117
123 void spawn(float pos, float baseVel, CHSV baseColor, u32 lifetime);
124
126 void update(u32 now, u16 numLeds, float speedMultiplier, bool cyclical);
127
129 void draw(fl::span<CRGB> leds, u32 now, u16 numLeds);
130 };
131
133 u16 mLifetimeMs = 4000;
138};
139
140} // namespace fl
fl::CRGB leds[NUM_LEDS]
uint16_t speed
Definition Noise.ino:66
Fx1d(u16 numLeds)
Definition fx1d.h:12
~Particles1d() FL_NOEXCEPT
void setSpeed(float speed)
Set speed multiplier (1.0 = normal, >1.0 = faster, <1.0 = slower)
fl::vector< Particle > mParticles
Particle pool (oldest particle reused when full)
Definition particles.h:137
void setCyclical(bool cyclical)
Set cyclical mode (true = wrap around, false = stop at edges)
u8 mFadeRate
Fade amount per frame (0-255, higher = shorter trails)
Definition particles.h:132
Particles1d(u16 num_leds, u8 max_particles=10, u8 fade_rate=2)
void setFadeRate(u8 fade_rate)
Set fade rate for trails (0-255, higher = shorter trails)
u8 mOverdrawCount
Number of update/draw cycles per frame (higher = smoother trails, more CPU)
Definition particles.h:134
u16 mLifetimeMs
Average particle lifetime in milliseconds.
Definition particles.h:133
void setOverdrawCount(u8 count)
Set overdraw count (higher = smoother trails, more CPU)
float mSpeedMultiplier
Global speed multiplier (1.0 = normal, >1.0 = faster, <1.0 = slower)
Definition particles.h:135
bool mCyclical
Wrap mode: true = wrap around, false = stop at edges.
Definition particles.h:136
void spawnRandomParticle()
Spawn a particle with random position, velocity, color, and lifetime.
fl::string fxName() const override
void draw(DrawContext context) override
Update and render all particles with overdraw technique.
void setLifetime(u16 lifetime_ms)
Set average particle lifetime in milliseconds.
Power-based particle system for 1D LED strips creating organic light effects.
Definition particles.h:52
fl::hsv8 CHSV
Definition chsv.h:11
unsigned char u8
Definition stdint.h:131
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
void draw(fl::span< CRGB > leds, u32 now, u16 numLeds)
Render particle with sub-pixel accuracy and power-modulated color.
CHSV baseColor
Base color (HSV) - saturation increases with age.
Definition particles.h:105
void update(u32 now, u16 numLeds, float speedMultiplier, bool cyclical)
Update position based on velocity × power.
void spawn(u16 numLeds)
Spawn with random position, velocity, color, and lifetime.
float getPower(u32 now) const
bool active
Active flag (false = available for reuse)
Definition particles.h:108
float pos
Position (floating point for sub-pixel rendering)
Definition particles.h:103
float baseVel
Base velocity (actual velocity = baseVel × power)
Definition particles.h:104
u32 lifetime
Lifespan in milliseconds.
Definition particles.h:107
u32 birthTime
Spawn timestamp (ms)
Definition particles.h:106
Individual particle with power-based lifecycle.
Definition particles.h:102