FastLED 3.10.8
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) FL_NO_EXCEPT;
58
60
63 void draw(DrawContext context) FL_NO_EXCEPT override;
64
74
77 void setLifetime(u16 lifetime_ms) FL_NO_EXCEPT;
78
82
85 void setSpeed(float speed) FL_NO_EXCEPT;
86
89 void setFadeRate(u8 fade_rate) FL_NO_EXCEPT;
90
93 void setCyclical(bool cyclical) FL_NO_EXCEPT;
94
95 fl::string fxName() const FL_NO_EXCEPT override;
96
97 private:
102 struct Particle {
103 float pos;
104 float baseVel;
108 bool active;
109
111
113 float getPower(u32 now) const FL_NO_EXCEPT;
114
116 void spawn(u16 numLeds) FL_NO_EXCEPT;
117
123 void spawn(float pos, float baseVel, CHSV baseColor, u32 lifetime) FL_NO_EXCEPT;
124
126 void update(u32 now, u16 numLeds, float speedMultiplier, bool cyclical) FL_NO_EXCEPT;
127
129 void draw(fl::span<CRGB> leds, u32 now, u16 numLeds) FL_NO_EXCEPT;
130 };
131
133 u16 mLifetimeMs = 4000;
138};
139
140} // namespace fl
CRGB leds[1]
uint16_t speed
Definition Noise.ino:72
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
Particles1d(u16 num_leds, u8 max_particles=10, u8 fade_rate=2) FL_NO_EXCEPT
void setSpeed(float speed) FL_NO_EXCEPT
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
u8 mFadeRate
Fade amount per frame (0-255, higher = shorter trails)
Definition particles.h:132
fl::string fxName() const FL_NO_EXCEPT override
~Particles1d() FL_NO_EXCEPT
void setLifetime(u16 lifetime_ms) FL_NO_EXCEPT
Set average particle lifetime in milliseconds.
void spawnRandomParticle() FL_NO_EXCEPT
Spawn a particle with random position, velocity, color, and lifetime.
void setCyclical(bool cyclical) FL_NO_EXCEPT
Set cyclical mode (true = wrap around, false = stop at edges)
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
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 draw(DrawContext context) FL_NO_EXCEPT override
Update and render all particles with overdraw technique.
void setFadeRate(u8 fade_rate) FL_NO_EXCEPT
Set fade rate for trails (0-255, higher = shorter trails)
void setOverdrawCount(u8 count) FL_NO_EXCEPT
Set overdraw count (higher = smoother trails, more CPU)
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
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
CHSV baseColor
Base color (HSV) - saturation increases with age.
Definition particles.h:105
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
void draw(fl::span< CRGB > leds, u32 now, u16 numLeds) FL_NO_EXCEPT
Render particle with sub-pixel accuracy and power-modulated color.
void update(u32 now, u16 numLeds, float speedMultiplier, bool cyclical) FL_NO_EXCEPT
Update position based on velocity × power.
u32 lifetime
Lifespan in milliseconds.
Definition particles.h:107
u32 birthTime
Spawn timestamp (ms)
Definition particles.h:106
void spawn(u16 numLeds) FL_NO_EXCEPT
Spawn with random position, velocity, color, and lifetime.
float getPower(u32 now) const FL_NO_EXCEPT
Individual particle with power-based lifecycle.
Definition particles.h:102