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

◆ fill_rainbow_circular() [1/3]

void fl::fill_rainbow_circular ( CHSV * targetArray,
int numToFill,
fl::u8 initialhue,
bool reversed = false )

Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the strip and the beginning.

The colors making up the rainbow are at full saturation and full value (brightness).

Parameters
targetArraya pointer to the LED array to fill
numToFillthe number of LEDs to fill in the array
initialhuethe starting hue for the rainbow
reversedwhether to progress through the rainbow hues backwards

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

82 {
83 if (numToFill == 0)
84 return; // avoiding div/0
85
86 CHSV hsv;
87 hsv.hue = initialhue;
88 hsv.val = 255;
89 hsv.sat = 240;
90
91 const u16 hueChange =
92 65535 / (u16)numToFill; // hue change for each LED, * 256 for
93 // precision (256 * 256 - 1)
94 u16 hueOffset = 0; // offset for hue value, with precision (*256)
95
96 for (int i = 0; i < numToFill; ++i) {
97 targetArray[i] = hsv;
98 if (reversed)
99 hueOffset -= hueChange;
100 else
101 hueOffset += hueChange;
102 hsv.hue = initialhue +
103 (u8)(hueOffset >>
104 8); // assign new hue with precise offset (as 8-bit)
105 }
106}
fl::hsv8 CHSV
Definition chsv.h:11
unsigned char u8
Definition stdint.h:131

References FL_NO_EXCEPT.