Fill a range of LEDs with a smooth HSV gradient between two HSV colors.
89 {
90
91 if (endpos < startpos) {
94 endcolor = startcolor;
95 endpos = startpos;
97 startcolor = tc;
98 }
99
100
101
102
103
104 if (endcolor.value == 0 || endcolor.saturation == 0) {
105 endcolor.hue = startcolor.hue;
106 }
107
108
109
110
111
112 if (startcolor.value == 0 || startcolor.saturation == 0) {
113 startcolor.hue = endcolor.hue;
114 }
115
119
120 satdistance87 = (endcolor.sat - startcolor.sat) << 7;
121 valdistance87 = (endcolor.val - startcolor.val) << 7;
122
123 fl::u8 huedelta8 = endcolor.hue - startcolor.hue;
124
127 if (huedelta8 > 127) {
129 }
130 }
131
134 if (huedelta8 < 128) {
136 }
137 }
138
140 huedistance87 = huedelta8 << 7;
141 } else
142 {
143 huedistance87 = (
fl::u8)(256 - huedelta8) << 7;
144 huedistance87 = -huedistance87;
145 }
146
147 u16 pixeldistance = endpos - startpos;
148 i16 divisor = pixeldistance ? pixeldistance : 1;
149
150#if FASTLED_USE_32_BIT_GRADIENT_FILL
151
152 i32 huedelta823 = (huedistance87 * 65536) / divisor;
153 i32 satdelta823 = (satdistance87 * 65536) / divisor;
154 i32 valdelta823 = (valdistance87 * 65536) / divisor;
155
156 huedelta823 *= 2;
157 satdelta823 *= 2;
158 valdelta823 *= 2;
159 u32 hue824 = static_cast<u32>(startcolor.hue) << 24;
160 u32 sat824 = static_cast<u32>(startcolor.sat) << 24;
161 u32 val824 = static_cast<u32>(startcolor.val) << 24;
162 for (u16 i = startpos; i <= endpos; ++i) {
163 targetArray[i] =
CHSV(hue824 >> 24, sat824 >> 24, val824 >> 24);
164 hue824 += huedelta823;
165 sat824 += satdelta823;
166 val824 += valdelta823;
167 }
168#else
169
170 saccum87 huedelta87 = huedistance87 / divisor;
171 saccum87 satdelta87 = satdistance87 / divisor;
172 saccum87 valdelta87 = valdistance87 / divisor;
173
174 huedelta87 *= 2;
175 satdelta87 *= 2;
176 valdelta87 *= 2;
177
178 accum88 hue88 = startcolor.hue << 8;
179 accum88 sat88 = startcolor.sat << 8;
180 accum88 val88 = startcolor.val << 8;
181 for (u16 i = startpos; i <= endpos; ++i) {
182 targetArray[i] =
CHSV(hue88 >> 8, sat88 >> 8, val88 >> 8);
183 hue88 += huedelta87;
184 sat88 += satdelta87;
185 val88 += valdelta87;
186 }
187#endif
188}
@ SHORTEST_HUES
Hue goes whichever way is shortest.
@ LONGEST_HUES
Hue goes whichever way is longest.
@ FORWARD_HUES
Hue always goes clockwise around the color wheel.
@ BACKWARD_HUES
Hue always goes counter-clockwise around the color wheel.
#define saccum87
ANSI: signed short _Accum.
u16 accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).