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

◆ draw()

void fl::Fire2012::draw ( DrawContext context)
inlineoverridevirtual
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 60 of file fire2012.h.

60 {
61 fl::span<CRGB> leds = context.leds;
62 if (leds.empty()) {
63 return;
64 }
65
66 // Step 1. Cool down every cell a little
67 for (u16 i = 0; i < mNumLeds; i++) {
68 heat[i] =
69 qsub8(heat[i], random8(0, ((cooling * 10) / mNumLeds) + 2));
70 }
71
72 // Step 2. Heat from each cell drifts 'up' and diffuses a little
73 for (u16 k = mNumLeds - 1; k >= 2; k--) {
74 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
75 }
76
77 // Step 3. Randomly ignite new 'sparks' of heat near the bottom
78 if (random8() < sparking) {
79 int y = random8(7);
80 heat[y] = qadd8(heat[y], random8(160, 255));
81 }
82
83 // Step 4. Map from heat cells to LED colors
84 for (u16 j = 0; j < mNumLeds; j++) {
85 // Scale the heat value from 0-255 down to 0-240
86 // for best results with color palettes.
87 u8 colorindex = scale8(heat[j], 240);
88 CRGB color = ColorFromPalette(palette, colorindex);
89 int pixelnumber;
91 pixelnumber = (mNumLeds - 1) - j;
92 } else {
93 pixelnumber = j;
94 }
95 leds[pixelnumber] = color;
96 }
97 }
fl::CRGB leds[NUM_LEDS]
CRGBPalette16 palette
Definition fire2012.h:106
fl::vector_psram< u8 > heat
Definition fire2012.h:102
bool reverse_direction
Definition fire2012.h:105
u16 mNumLeds
Definition fx.h:53
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
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)

References fl::ColorFromPalette(), cooling, heat, fl::DrawContext::leds, leds, fl::Fx::mNumLeds, palette, random8(), reverse_direction, sparking, and fl::y.

+ Here is the call graph for this function: