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

◆ draw()

void fl::PerlinParticlePunch::draw ( DrawContext context)
overridevirtual
Parameters
nowThe current time in milliseconds. Fx writers are encouraged to use this instead of millis() directly as this will more deterministic behavior.

Implements fl::Fx.

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

413 {
414 fl::span<CRGB> leds = context.leds;
415 if (leds.empty() || mNumLeds == 0) {
416 return;
417 }
418 u32 now = context.now;
419
420 // --- Layer 1: Perlin noise background (fresh each frame) ---
421 noiseCircleDraw(now, leds);
422
423 // --- Trail buffer decay ---
424 // Use the larger of the two trail intensities for the shared buffer.
425 // Higher intensity value = less fade per frame = longer trails.
429 u8 decayRate = 255 - trailIntensity;
430 fadeToBlackBy(mTrailBuffer.data(), mNumLeds, decayRate);
431
432 // --- Layer 2: Ambient particles ---
433 for (u16 i = 0; i < (u16)mAmbientParticles.size(); ++i) {
435 if (!p.alive)
436 continue;
437 // Physics update
438 p.velocity *= mDrag;
439 p.position += p.velocity;
440 p.brightness *= mAmbientBrightnessDecay;
441 if (p.position >= float(mNumLeds) || p.position < 0.0f ||
442 p.brightness < 8.0f || p.velocity < mMinVelocity) {
443 p.alive = false;
444 continue;
445 }
446 renderAmbient(p);
447 }
448
449 // --- Layer 3: Meteors ---
450 for (u16 i = 0; i < (u16)mMeteorParticles.size(); ++i) {
452 if (!m.alive)
453 continue;
454 // Debris spawn check before physics update
455 if (m.shouldSpawnDebris()) {
456 spawnDebrisFromMeteor(m, now);
457 }
458 // Physics update
459 m.velocity *= mMeteorDrag;
460 m.position += m.velocity;
461 m.frameCounter++;
462 if (m.position >= float(mNumLeds) || m.velocity < mMinVelocity) {
463 m.alive = false;
464 continue;
465 }
466 renderMeteor(m);
467 }
468
469 // --- Debris ---
470 for (u16 i = 0; i < (u16)mDebrisParticles.size(); ++i) {
472 if (!d.alive)
473 continue;
474 // Physics update
475 d.position += d.velocity;
476 d.velocity *= mDebrisVelocityDecay;
477 d.brightness *= mDebrisBrightnessDecay;
478 if (d.brightness < 5.0f || d.position >= float(mNumLeds)) {
479 d.alive = false;
480 continue;
481 }
482 renderDebris(d);
483 }
484
485 // --- Composite: max(noise, trail) per channel ---
486 for (u16 i = 0; i < mNumLeds; ++i) {
487 if (mTrailBuffer[i].r > leds[i].r)
488 leds[i].r = mTrailBuffer[i].r;
489 if (mTrailBuffer[i].g > leds[i].g)
490 leds[i].g = mTrailBuffer[i].g;
491 if (mTrailBuffer[i].b > leds[i].b)
492 leds[i].b = mTrailBuffer[i].b;
493 }
494}
fl::CRGB leds[NUM_LEDS]
u16 mNumLeds
Definition fx.h:53
fl::vector< DebrisParticle > mDebrisParticles
fl::vector< MeteorParticle > mMeteorParticles
void spawnDebrisFromMeteor(MeteorParticle &m, u32 now)
void noiseCircleDraw(u32 now, fl::span< CRGB > dst)
void renderMeteor(const MeteorParticle &m)
void renderDebris(const DebrisParticle &d)
void renderAmbient(const AmbientParticle &p)
fl::vector< AmbientParticle > mAmbientParticles
unsigned char u8
Definition stdint.h:131
void fadeToBlackBy(CRGB *leds, fl::u16 num_leds, fl::u8 fadeBy)

References fl::PerlinParticlePunch::AmbientParticle::alive, fl::PerlinParticlePunch::DebrisParticle::alive, fl::PerlinParticlePunch::MeteorParticle::alive, fl::PerlinParticlePunch::AmbientParticle::brightness, fl::PerlinParticlePunch::DebrisParticle::brightness, fl::fadeToBlackBy(), fl::PerlinParticlePunch::MeteorParticle::frameCounter, fl::DrawContext::leds, leds, mAmbientBrightnessDecay, mAmbientParticles, mAmbientTrailIntensity, mDebrisBrightnessDecay, mDebrisParticles, mDebrisVelocityDecay, mDrag, mMeteorDrag, mMeteorParticles, mMeteorTrailIntensity, mMinVelocity, fl::Fx::mNumLeds, mTrailBuffer, noiseCircleDraw(), fl::DrawContext::now, fl::PerlinParticlePunch::AmbientParticle::position, fl::PerlinParticlePunch::DebrisParticle::position, fl::PerlinParticlePunch::MeteorParticle::position, renderAmbient(), renderDebris(), renderMeteor(), fl::PerlinParticlePunch::MeteorParticle::shouldSpawnDebris(), spawnDebrisFromMeteor(), fl::PerlinParticlePunch::AmbientParticle::velocity, fl::PerlinParticlePunch::DebrisParticle::velocity, and fl::PerlinParticlePunch::MeteorParticle::velocity.

Referenced by ~PerlinParticlePunch().

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