12 if (v <= 0.0f)
return 0;
13 if (v >= 255.0f)
return 255;
73 CRGBPalette16 defaultPalette(
CRGB(0, 0, 40),
CRGB(0, 40, 120),
83 return "PerlinParticlePunch";
114 float diff = 1.0f - drag;
156 float jitter = float(
random8(80, 120)) / 100.0f;
167 if (intensity < 0.0f)
169 if (intensity > 1.0f)
187 for (u16 i = 0; i < n; ++i) {
199 for (u16 i = 0; i < n; ++i) {
211 for (u16 i = 0; i < n; ++i) {
228 return (
x - in_min) / (in_max - in_min) * (out_max - out_min) + out_min;
243 constexpr s16x16 one(1.0f);
256 constexpr s16x16 two_pi(6.2831853f);
258 s16x16 theta = -time_factor;
259 constexpr s16x16 threshold(32.0f);
260 constexpr s16x16 zero(0.0f);
261 constexpr s16x16 max_val(255.0f);
262 for (u16 i = 0; i <
mNumLeds; ++i) {
264 if (val < threshold) {
267 val =
mapf(val, threshold, max_val, zero, max_val);
272 theta = theta +
step;
291 float frac = p.
position - float(center);
297 int idx = center -
offset;
303 CRGB pixel = baseColor;
304 pixel.
nscale8(clamp_u8(falloff * 255.0f));
307 if (
offset == 0 && frac > 0.01f) {
308 int nextIdx = center + 1;
310 CRGB subPixel = pixel;
311 subPixel.
nscale8(clamp_u8(frac * 255.0f));
314 pixel.
nscale8(clamp_u8((1.0f - frac) * 255.0f));
325 static const float kGaussian[] = {0.15f, 0.60f, 1.0f, 0.60f, 0.15f};
327 int idx = center +
offset;
330 float weight = kGaussian[
offset + 2];
333 bri = scale8(bri,
random8(153, 255));
341 int tailPixels = int(tailLen);
342 for (
int i = 1; i <= tailPixels; ++i) {
343 int idx = center - i;
350 float t = float(i) / float(tailPixels);
351 fract8 blendAmt = clamp_u8(
t * 255.0f);
355 tailColor.
nscale8(clamp_u8(bri * 255.0f));
362 float frac = d.
position - float(idx);
369 main.nscale8(clamp_u8((1.0f - frac) * 255.0f));
372 int nextIdx = idx + 1;
373 if (nextIdx >= 0 && nextIdx < mNumLeds && frac > 0.01f) {
375 sub.
nscale8(clamp_u8(frac * 255.0f));
386 u8 maxOffset = clamp_u8(tailLen);
389 float spawnOffset = float(
random8(2, maxOffset));
390 float spawnPos = m.
position - spawnOffset;
395 float t = spawnOffset / tailLen;
398 fract8 blendAmt = clamp_u8(
t * 255.0f);
405 d->
color = debrisColor;
418 u32 now = context.
now;
429 u8 decayRate = 255 - trailIntensity;
486 for (u16 i = 0; i <
mNumLeds; ++i) {
UINumberField palette("Palette", 0, 0, 2)
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.
DebrisParticle * tryAllocateDebris()
MeteorParticle * tryAllocateMeteor()
void setDebrisBrightnessDecay(float decay)
Per-frame brightness decay for debris particles. Default 0.90.
float mDebrisBrightnessDecay
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
PerlinParticlePunch(u16 num_leds)
static void writeMax(CRGB &dst, const CRGB &src)
CRGBPalette16 mAmbientPalette
float mDebrisVelocityDecay
CRGBPalette16 mNoisePalette
fl::vector< CRGB > mTrailBuffer
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).
float mAmbientBrightnessDecay
AmbientParticle * tryAllocateAmbient()
void setSpeed(float speed)
Set velocity multiplier. Default 1.0.
void renderDebris(const DebrisParticle &d)
u8 mAmbientTrailIntensity
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
static constexpr i32 SCALE
static FASTLED_FORCE_INLINE void sincos(s16x16 angle, s16x16 &out_sin, s16x16 &out_cos) FL_NOEXCEPT
constexpr i32 to_int() const FL_NOEXCEPT
static constexpr int FRAC_BITS
static constexpr FASTLED_FORCE_INLINE s16x16 from_raw(i32 raw) FL_NOEXCEPT
constexpr i32 raw() const FL_NOEXCEPT
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
fl::u16 inoise16(fl::u32 x, fl::u32 y, fl::u32 z, fl::u32 t)
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
u8 fract8
Fixed-Point Fractional Types.
void fadeToBlackBy(CRGB *leds, fl::u16 num_leds, fl::u8 fadeBy)
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NOEXCEPT
Base definition for an LED controller.
Audio-reactive perlin noise background with ambient particles and beat meteor overlay.
CRGB & nscale8(u8 scaledown) FL_NOEXCEPT
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Representation of an 8-bit RGB pixel (Red, Green, Blue)
bool shouldSpawnDebris() const