FastLED 3.9.15
Loading...
Searching...
No Matches
perlin_particle_punch.h
Go to the documentation of this file.
1#pragma once
2
7
8#include "fl/fx/fx1d.h"
9#include "fl/gfx/colorutils.h"
11#include "fl/stl/vector.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15
17
18class PerlinParticlePunch : public Fx1d {
19 public:
20 PerlinParticlePunch(u16 num_leds);
22
23 void draw(DrawContext context) override;
24 fl::string fxName() const override;
25
26 // --- Particle spawning (called from sketch via detector callbacks) ---
27
30 void spawnAmbient(float intensity = 0.5f);
31
34 void spawnMeteor(float intensity = 1.0f);
35
36 // --- Perlin noise layer control ---
37
39 void setTimeMultiplier(float mult);
40
42 void setNoisePalette(const CRGBPalette16 &palette);
43
44 // --- Ambient control ---
45
47 void setAmbientPalette(const CRGBPalette16 &palette);
48
49 // --- Meteor control ---
50
52 void setMeteorGradient(CRGB headColor, CRGB midColor, CRGB tailColor);
53
54 // --- Physics tuning ---
55
58 void setDrag(float drag);
59
61 void setSpeed(float speed);
62
63 // --- Trail control ---
64
66 void setAmbientTrailIntensity(u8 intensity);
67
69 void setMeteorTrailIntensity(u8 intensity);
70
71 // --- Particle lifetime tuning ---
72
76
79 void setMinVelocity(float minVel);
80
83
85 void setDebrisVelocityDecay(float decay);
86
87 private:
88 struct AmbientParticle;
89 struct MeteorParticle;
90 struct DebrisParticle;
91
92 // Perlin noise
93 float mTimeMultiplier = 1.0f;
94 CRGBPalette16 mNoisePalette;
95
96 // Ambient
97 CRGBPalette16 mAmbientPalette;
98 float mDrag = 0.95f;
99 float mSpeed = 1.0f;
101
102 // Meteor
103 CRGB mMeteorHeadColor = CRGB(255, 255, 255);
104 CRGB mMeteorMidColor = CRGB(140, 180, 255);
106 float mMeteorDrag = 0.92f;
108
109 // Particle lifetime
111 float mMinVelocity = 0.05f;
113 float mDebrisVelocityDecay = 0.95f;
114
115 // Particle pools
119
120 // Trail buffer (persistent between frames)
122
123 // Noise helpers (kept from original, using s16x16)
124 static s16x16 mapf(s16x16 x, s16x16 in_min, s16x16 in_max, s16x16 out_min,
125 s16x16 out_max);
126 s16x16 circleNoiseGen(u32 now, s16x16 theta) const;
127 void noiseCircleDraw(u32 now, fl::span<CRGB> dst);
128
129 // Particle helpers
133 void renderAmbient(const AmbientParticle &p);
134 void renderMeteor(const MeteorParticle &m);
135 void renderDebris(const DebrisParticle &d);
136 void spawnDebrisFromMeteor(MeteorParticle &m, u32 now);
137
138 static void writeMax(CRGB &dst, const CRGB &src);
139};
140
141} // namespace fl
UINumberField palette("Palette", 0, 0, 2)
uint16_t speed
Definition Noise.ino:66
Fx1d(u16 numLeds)
Definition fx1d.h:12
void spawnMeteor(float intensity=1.0f)
Spawn a BEAT meteor at position 0, traveling toward end of strip.
void setMeteorGradient(CRGB headColor, CRGB midColor, CRGB tailColor)
Set the meteor color gradient: head → mid → tail.
fl::vector< DebrisParticle > mDebrisParticles
void setAmbientTrailIntensity(u8 intensity)
Ambient trail intensity: 0 = no trail, 255 = long persistent trail.
fl::vector< MeteorParticle > mMeteorParticles
void spawnDebrisFromMeteor(MeteorParticle &m, u32 now)
void setAmbientBrightnessDecay(float decay)
Per-frame brightness decay for ambient particles.
void setDebrisBrightnessDecay(float decay)
Per-frame brightness decay for debris particles. Default 0.90.
void noiseCircleDraw(u32 now, fl::span< CRGB > dst)
void renderMeteor(const MeteorParticle &m)
void setDebrisVelocityDecay(float decay)
Per-frame velocity decay for debris particles. Default 0.95.
void draw(DrawContext context) override
static s16x16 mapf(s16x16 x, s16x16 in_min, s16x16 in_max, s16x16 out_min, s16x16 out_max)
s16x16 circleNoiseGen(u32 now, s16x16 theta) const
static void writeMax(CRGB &dst, const CRGB &src)
void setNoisePalette(const CRGBPalette16 &palette)
Set palette for Perlin noise background.
void setMinVelocity(float minVel)
Minimum velocity before a particle dies.
~PerlinParticlePunch() FL_NOEXCEPT
void setAmbientPalette(const CRGBPalette16 &palette)
Set palette for ambient particles.
void setDrag(float drag)
Set per-frame drag for ambient particles (0.0 = instant stop, 1.0 = no drag).
void setSpeed(float speed)
Set velocity multiplier. Default 1.0.
void renderDebris(const DebrisParticle &d)
void renderAmbient(const AmbientParticle &p)
void setTimeMultiplier(float mult)
Set time multiplier for noise evolution (1.0 = normal, >1 = warp).
fl::string fxName() const override
void spawnAmbient(float intensity=0.5f)
Spawn an ambient particle at a random position.
void setMeteorTrailIntensity(u8 intensity)
Meteor trail intensity: controls how long meteor/debris trails linger.
fl::vector< AmbientParticle > mAmbientParticles
Utility functions for color fill, palettes, blending, and more.
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