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 61 of file fire2012.h.

61 {
62 CRGB *leds = context.leds;
63 if (leds == nullptr) {
64 return;
65 }
66
67 // Step 1. Cool down every cell a little
68 for (uint16_t i = 0; i < mNumLeds; i++) {
69 heat[i] =
70 qsub8(heat[i], random8(0, ((cooling * 10) / mNumLeds) + 2));
71 }
72
73 // Step 2. Heat from each cell drifts 'up' and diffuses a little
74 for (uint16_t k = mNumLeds - 1; k >= 2; k--) {
75 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
76 }
77
78 // Step 3. Randomly ignite new 'sparks' of heat near the bottom
79 if (random8() < sparking) {
80 int y = random8(7);
81 heat[y] = qadd8(heat[y], random8(160, 255));
82 }
83
84 // Step 4. Map from heat cells to LED colors
85 for (uint16_t j = 0; j < mNumLeds; j++) {
86 // Scale the heat value from 0-255 down to 0-240
87 // for best results with color palettes.
88 uint8_t colorindex = scale8(heat[j], 240);
89 CRGB color = ColorFromPalette(palette, colorindex);
90 int pixelnumber;
92 pixelnumber = (mNumLeds - 1) - j;
93 } else {
94 pixelnumber = j;
95 }
96 leds[pixelnumber] = color;
97 }
98 }
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
CRGBPalette16 palette
Definition fire2012.h:107
uint8_t cooling
Definition fire2012.h:104
fl::scoped_array< uint8_t > heat
Definition fire2012.h:103
bool reverse_direction
Definition fire2012.h:106
uint8_t sparking
Definition fire2012.h:105
uint16_t mNumLeds
Definition fx.h:50
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
Definition math8.h:31
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:103
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:44
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:34

References ColorFromPalette(), cooling, heat, fl::_DrawContext::leds, leds, fl::Fx::mNumLeds, palette, qadd8(), qsub8(), random8(), reverse_direction, scale8(), sparking, and y.

+ Here is the call graph for this function: