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

◆ renderAmbient()

void fl::PerlinParticlePunch::renderAmbient ( const AmbientParticle & p)
private

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

289 {
290 int center = int(p.position);
291 float frac = p.position - float(center);
292 u8 bri = clamp_u8(p.brightness);
293 CRGB baseColor =
294 ColorFromPalette(mAmbientPalette, p.paletteIndex, bri, LINEARBLEND);
295
296 for (int offset = 0; offset < p.headWidth; ++offset) {
297 int idx = center - offset; // trail extends behind (toward pos 0)
298 if (idx < 0 || idx >= mNumLeds)
299 continue;
300
301 // Linear falloff: 100% at head → 20% at tail of gradient
302 float falloff = 1.0f - (float(offset) / float(p.headWidth)) * 0.8f;
303 CRGB pixel = baseColor;
304 pixel.nscale8(clamp_u8(falloff * 255.0f));
305
306 // Sub-pixel blending for the leading edge
307 if (offset == 0 && frac > 0.01f) {
308 int nextIdx = center + 1;
309 if (nextIdx < mNumLeds) {
310 CRGB subPixel = pixel;
311 subPixel.nscale8(clamp_u8(frac * 255.0f));
312 writeMax(mTrailBuffer[nextIdx], subPixel);
313 }
314 pixel.nscale8(clamp_u8((1.0f - frac) * 255.0f));
315 }
316
317 writeMax(mTrailBuffer[idx], pixel);
318 }
319}
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)
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
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::PerlinParticlePunch::AmbientParticle::brightness, fl::ColorFromPalette(), fl::PerlinParticlePunch::AmbientParticle::headWidth, mAmbientPalette, fl::Fx::mNumLeds, mTrailBuffer, fl::CRGB::nscale8(), offset(), fl::PerlinParticlePunch::AmbientParticle::paletteIndex, fl::PerlinParticlePunch::AmbientParticle::position, and writeMax().

Referenced by draw().

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