FastLED 3.10.8
Loading...
Searching...
No Matches

◆ fill_gradient_RGB()

void fl::fill_gradient_RGB ( CRGB * leds,
u16 startpos,
CRGB startcolor,
u16 endpos,
CRGB endcolor )

Fill a range of LEDs with a smooth RGB gradient between two RGB colors.

Unlike HSV, there is no "color wheel" in RGB space, and therefore there's only one "direction" for the gradient to go. This means there's no TGradientDirectionCode parameter for direction.

Parameters
ledsa pointer to the LED array to fill
startposthe starting position in the array
startcolorthe starting color for the gradient
endposthe ending position in the array
endcolorthe end color for the gradient

Definition at line 108 of file fill.cpp.hpp.

109 {
110 // if the points are in the wrong order, straighten them
111 if (endpos < startpos) {
112 u16 t = endpos;
113 CRGB tc = endcolor;
114 endcolor = startcolor;
115 endpos = startpos;
116 startpos = t;
117 startcolor = tc;
118 }
119
120 saccum87 rdistance87;
121 saccum87 gdistance87;
122 saccum87 bdistance87;
123
124 // Each difference is in [-255, 255], so scaling fits signed Q8.7.
125 rdistance87 = (endcolor.r - startcolor.r) * 128;
126 gdistance87 = (endcolor.g - startcolor.g) * 128;
127 bdistance87 = (endcolor.b - startcolor.b) * 128;
128
129 u16 pixeldistance = endpos - startpos;
130 i16 divisor = pixeldistance ? pixeldistance : 1;
131
132 saccum87 rdelta87 = rdistance87 / divisor;
133 saccum87 gdelta87 = gdistance87 / divisor;
134 saccum87 bdelta87 = bdistance87 / divisor;
135
136 rdelta87 *= 2;
137 gdelta87 *= 2;
138 bdelta87 *= 2;
139
140 accum88 r88 = startcolor.r << 8;
141 accum88 g88 = startcolor.g << 8;
142 accum88 b88 = startcolor.b << 8;
143 for (u16 i = startpos; i <= endpos; ++i) {
144 leds[i] = CRGB(r88 >> 8, g88 >> 8, b88 >> 8);
145 r88 += rdelta87;
146 g88 += gdelta87;
147 b88 += bdelta87;
148 }
149}
CRGB leds[1]
static uint32_t t
Definition Luminova.h:55
#define saccum87
ANSI: signed short _Accum.
Definition fill.h:19
fl::CRGB CRGB
Definition crgb.h:25
u16 accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Definition stdint.h:181

Referenced by FL_DISABLE_WARNING().

+ Here is the caller graph for this function: