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

◆ HeatColor()

CRGB HeatColor ( uint8_t temperature)

Approximates a "black body radiation" spectrum for a given "heat" level.

This is useful for animations of "fire". Heat is specified as an arbitrary scale from 0 (cool) to 255 (hot). This is NOT a chromatically correct "black body radiation" spectrum, but it's surprisingly close, and it's fast and small.

Definition at line 543 of file colorutils.cpp.

544{
545 CRGB heatcolor;
546
547 // Scale 'heat' down from 0-255 to 0-191,
548 // which can then be easily divided into three
549 // equal 'thirds' of 64 units each.
550 uint8_t t192 = scale8_video( temperature, 191);
551
552 // calculate a value that ramps up from
553 // zero to 255 in each 'third' of the scale.
554 uint8_t heatramp = t192 & 0x3F; // 0..63
555 heatramp <<= 2; // scale up to 0..252
556
557 // now figure out which third of the spectrum we're in:
558 if( t192 & 0x80) {
559 // we're in the hottest third
560 heatcolor.r = 255; // full red
561 heatcolor.g = 255; // full green
562 heatcolor.b = heatramp; // ramp up blue
563
564 } else if( t192 & 0x40 ) {
565 // we're in the middle third
566 heatcolor.r = 255; // full red
567 heatcolor.g = heatramp; // ramp up green
568 heatcolor.b = 0; // no blue
569
570 } else {
571 // we're in the coolest third
572 heatcolor.r = heatramp; // ramp up red
573 heatcolor.g = 0; // no green
574 heatcolor.b = 0; // no blue
575 }
576
577 return heatcolor;
578}
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_video(uint8_t i, fract8 scale)
The "video" version of scale8() guarantees that the output will be only be zero if one or both of the...
Definition scale8.h:117
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

References scale8_video().

Referenced by Fire2012().

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