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

◆ fill_gradient_RGB() [4/4]

void fill_gradient_RGB ( CRGB * leds,
uint16_t startpos,
CRGB startcolor,
uint16_t 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 145 of file colorutils.cpp.

148{
149 // if the points are in the wrong order, straighten them
150 if( endpos < startpos ) {
151 uint16_t t = endpos;
152 CRGB tc = endcolor;
153 endcolor = startcolor;
154 endpos = startpos;
155 startpos = t;
156 startcolor = tc;
157 }
158
159 saccum87 rdistance87;
160 saccum87 gdistance87;
161 saccum87 bdistance87;
162
163 rdistance87 = (endcolor.r - startcolor.r) << 7;
164 gdistance87 = (endcolor.g - startcolor.g) << 7;
165 bdistance87 = (endcolor.b - startcolor.b) << 7;
166
167 uint16_t pixeldistance = endpos - startpos;
168 int16_t divisor = pixeldistance ? pixeldistance : 1;
169
170 saccum87 rdelta87 = rdistance87 / divisor;
171 saccum87 gdelta87 = gdistance87 / divisor;
172 saccum87 bdelta87 = bdistance87 / divisor;
173
174 rdelta87 *= 2;
175 gdelta87 *= 2;
176 bdelta87 *= 2;
177
178 accum88 r88 = startcolor.r << 8;
179 accum88 g88 = startcolor.g << 8;
180 accum88 b88 = startcolor.b << 8;
181 for( uint16_t i = startpos; i <= endpos; ++i) {
182 leds[i] = CRGB( r88 >> 8, g88 >> 8, b88 >> 8);
183 r88 += rdelta87;
184 g88 += gdelta87;
185 b88 += bdelta87;
186 }
187}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define saccum87
ANSI: signed short _Accum.
Definition colorutils.h:170
uint16_t accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Definition types.h:58
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

References leds, and saccum87.

Referenced by CRGBPalette16::CRGBPalette16(), CRGBPalette16::CRGBPalette16(), CRGBPalette16::CRGBPalette16(), CRGBPalette256::CRGBPalette256(), CRGBPalette256::CRGBPalette256(), CRGBPalette256::CRGBPalette256(), CRGBPalette32::CRGBPalette32(), CRGBPalette32::CRGBPalette32(), CRGBPalette32::CRGBPalette32(), fill_gradient_RGB(), fill_gradient_RGB(), fill_gradient_RGB(), CRGBPalette16::loadDynamicGradientPalette(), CRGBPalette256::loadDynamicGradientPalette(), CRGBPalette32::loadDynamicGradientPalette(), CRGBPalette16::operator=(), CRGBPalette256::operator=(), and CRGBPalette32::operator=().

+ Here is the caller graph for this function: