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 CRGB *leds = context.leds;
62 if (leds == nullptr) {
63 return;
64 }
65
66 // Step 1. Cool down every cell a little
67 for (uint16_t 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 (uint16_t 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 (uint16_t 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 uint8_t 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 }
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
int y
Definition Audio.ino:72
CRGBPalette16 palette
Definition fire2012.h:106
uint8_t cooling
Definition fire2012.h:103
fl::scoped_array< uint8_t > heat
Definition fire2012.h:102
bool reverse_direction
Definition fire2012.h:105
uint8_t sparking
Definition fire2012.h:104
uint16_t mNumLeds
Definition fx.h:53
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
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:46
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:40
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)

References fl::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: