FastLED 3.9.15
Loading...
Searching...
No Matches

◆ renderMeteor()

void fl::PerlinParticlePunch::renderMeteor ( const MeteorParticle & m)
private

Definition at line 321 of file perlin_particle_punch.cpp.hpp.

321 {
322 int center = int(m.position);
323
324 // --- Head: 5-pixel gaussian kernel ---
325 static const float kGaussian[] = {0.15f, 0.60f, 1.0f, 0.60f, 0.15f};
326 for (int offset = -2; offset <= 2; ++offset) {
327 int idx = center + offset;
328 if (idx < 0 || idx >= mNumLeds)
329 continue;
330 float weight = kGaussian[offset + 2];
331 u8 bri = clamp_u8(255.0f * m.intensity * weight);
332 // Re-entry sparkle: random brightness jitter per pixel per frame
333 bri = scale8(bri, random8(153, 255));
334 CRGB headColor = mMeteorHeadColor;
335 headColor.nscale8(bri);
336 writeMax(mTrailBuffer[idx], headColor);
337 }
338
339 // --- Tail: gradient behind the head ---
340 float tailLen = m.tailLength();
341 int tailPixels = int(tailLen);
342 for (int i = 1; i <= tailPixels; ++i) {
343 int idx = center - i;
344 if (idx < 0)
345 break;
346 if (idx >= mNumLeds)
347 continue;
348
349 // t: 0.0 at head, 1.0 at tail tip
350 float t = float(i) / float(tailPixels);
351 fract8 blendAmt = clamp_u8(t * 255.0f);
352 CRGB tailColor = blend(mMeteorMidColor, mMeteorTailColor, blendAmt);
353 // Quadratic brightness falloff along tail
354 float bri = (1.0f - t * t) * m.intensity;
355 tailColor.nscale8(clamp_u8(bri * 255.0f));
356 writeMax(mTrailBuffer[idx], tailColor);
357 }
358}
u16 mNumLeds
Definition fx.h:53
static void writeMax(CRGB &dst, const CRGB &src)
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
u8 fract8
Fixed-Point Fractional Types.
Definition s16x16x4.h:161
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
CRGB & nscale8(u8 scaledown) FL_NOEXCEPT
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition crgb.cpp.hpp:88

References fl::blend(), fl::PerlinParticlePunch::MeteorParticle::intensity, mMeteorHeadColor, mMeteorMidColor, mMeteorTailColor, fl::Fx::mNumLeds, mTrailBuffer, fl::CRGB::nscale8(), offset(), fl::PerlinParticlePunch::MeteorParticle::position, random8(), fl::t, fl::PerlinParticlePunch::MeteorParticle::tailLength(), and writeMax().

Referenced by draw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: