MCPcopy Create free account
hub / github.com/FastLED/FastLED / draw

Method draw

src/fl/fx/1d/fire2012.h:60–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 ~Fire2012() FL_NOEXCEPT {}
59
60 void draw(DrawContext context) override {
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;
90 if (reverse_direction) {
91 pixelnumber = (mNumLeds - 1) - j;
92 } else {
93 pixelnumber = j;
94 }
95 leds[pixelnumber] = color;
96 }
97 }
98
99 fl::string fxName() const override { return "Fire2012"; }
100

Callers

nothing calls this directly

Calls 3

ColorFromPaletteFunction · 0.85
scale8Function · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected