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

◆ fill_gradient_RGB() [4/4]

void fl::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 107 of file fill.cpp.

108 {
109 // if the points are in the wrong order, straighten them
110 if (endpos < startpos) {
111 uint16_t t = endpos;
112 CRGB tc = endcolor;
113 endcolor = startcolor;
114 endpos = startpos;
115 startpos = t;
116 startcolor = tc;
117 }
118
119 saccum87 rdistance87;
120 saccum87 gdistance87;
121 saccum87 bdistance87;
122
123 rdistance87 = (endcolor.r - startcolor.r) << 7;
124 gdistance87 = (endcolor.g - startcolor.g) << 7;
125 bdistance87 = (endcolor.b - startcolor.b) << 7;
126
127 uint16_t pixeldistance = endpos - startpos;
128 int16_t divisor = pixeldistance ? pixeldistance : 1;
129
130 saccum87 rdelta87 = rdistance87 / divisor;
131 saccum87 gdelta87 = gdistance87 / divisor;
132 saccum87 bdelta87 = bdistance87 / divisor;
133
134 rdelta87 *= 2;
135 gdelta87 *= 2;
136 bdelta87 *= 2;
137
138 accum88 r88 = startcolor.r << 8;
139 accum88 g88 = startcolor.g << 8;
140 accum88 b88 = startcolor.b << 8;
141 for (uint16_t i = startpos; i <= endpos; ++i) {
142 leds[i] = CRGB(r88 >> 8, g88 >> 8, b88 >> 8);
143 r88 += rdelta87;
144 g88 += gdelta87;
145 b88 += bdelta87;
146 }
147}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define saccum87
ANSI: signed short _Accum.
Definition fill.h:9
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:55

References leds, and saccum87.

Referenced by fill_gradient_RGB(), fill_gradient_RGB(), and fill_gradient_RGB().

+ Here is the caller graph for this function: