FastLED 3.10.8
Loading...
Searching...
No Matches
fill.cpp.hpp
Go to the documentation of this file.
1
2
3#include "fl/stl/stdint.h"
4
5#include "fl/gfx/fill.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9
10void fill_solid(CRGB *targetArray, int numToFill,
11 const CRGB &color) FL_NO_EXCEPT {
12 for (int i = 0; i < numToFill; ++i) {
13 targetArray[i] = color;
14 }
15}
16
17void fill_solid(CHSV *targetArray, int numToFill,
18 const CHSV &color) FL_NO_EXCEPT {
19 for (int i = 0; i < numToFill; ++i) {
20 targetArray[i] = color;
21 }
22}
23
24// void fill_solid( CRGB* targetArray, int numToFill,
25// const CHSV& hsvColor)
26// {
27// fill_solid<CRGB>( targetArray, numToFill, (CRGB) hsvColor);
28// }
29
30void fill_rainbow(CRGB *targetArray, int numToFill, u8 initialhue,
31 u8 deltahue) FL_NO_EXCEPT {
32 CHSV hsv;
33 hsv.hue = initialhue;
34 hsv.val = 255;
35 hsv.sat = 240;
36 for (int i = 0; i < numToFill; ++i) {
37 targetArray[i] = hsv;
38 hsv.hue += deltahue;
39 }
40}
41
42void fill_rainbow(CHSV *targetArray, int numToFill, u8 initialhue,
43 u8 deltahue) FL_NO_EXCEPT {
44 CHSV hsv;
45 hsv.hue = initialhue;
46 hsv.val = 255;
47 hsv.sat = 240;
48 for (int i = 0; i < numToFill; ++i) {
49 targetArray[i] = hsv;
50 hsv.hue += deltahue;
51 }
52}
53
54void fill_rainbow_circular(CRGB *targetArray, int numToFill,
55 u8 initialhue, bool reversed) FL_NO_EXCEPT {
56 if (numToFill == 0)
57 return; // avoiding div/0
58
59 CHSV hsv;
60 hsv.hue = initialhue;
61 hsv.val = 255;
62 hsv.sat = 240;
63
64 const u16 hueChange =
65 65535 / (u16)numToFill; // hue change for each LED, * 256 for
66 // precision (256 * 256 - 1)
67 u16 hueOffset = 0; // offset for hue value, with precision (*256)
68
69 for (int i = 0; i < numToFill; ++i) {
70 targetArray[i] = hsv;
71 if (reversed)
72 hueOffset -= hueChange;
73 else
74 hueOffset += hueChange;
75 hsv.hue = initialhue +
76 (u8)(hueOffset >>
77 8); // assign new hue with precise offset (as 8-bit)
78 }
79}
80
81void fill_rainbow_circular(CHSV *targetArray, int numToFill,
82 u8 initialhue, bool reversed) FL_NO_EXCEPT {
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}
107
108void fill_gradient_RGB(CRGB *leds, u16 startpos, CRGB startcolor,
109 u16 endpos, CRGB endcolor) FL_NO_EXCEPT {
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}
150
151void fill_gradient_RGB(CRGB *leds, u16 numLeds, const CRGB &c1,
152 const CRGB &c2) FL_NO_EXCEPT {
153 u16 last = numLeds - 1;
154 fill_gradient_RGB(leds, 0, c1, last, c2);
155}
156
157void fill_gradient_RGB(CRGB *leds, u16 numLeds, const CRGB &c1,
158 const CRGB &c2, const CRGB &c3) FL_NO_EXCEPT {
159 u16 half = (numLeds / 2);
160 u16 last = numLeds - 1;
161 fill_gradient_RGB(leds, 0, c1, half, c2);
162 fill_gradient_RGB(leds, half, c2, last, c3);
163}
164
165void fill_gradient_RGB(CRGB *leds, u16 numLeds, const CRGB &c1,
166 const CRGB &c2, const CRGB &c3, const CRGB &c4) FL_NO_EXCEPT {
167 u16 onethird = (numLeds / 3);
168 u16 twothirds = ((numLeds * 2) / 3);
169 u16 last = numLeds - 1;
170 fill_gradient_RGB(leds, 0, c1, onethird, c2);
171 fill_gradient_RGB(leds, onethird, c2, twothirds, c3);
172 fill_gradient_RGB(leds, twothirds, c3, last, c4);
173}
174
175} // namespace fl
CRGB leds[1]
#define saccum87
ANSI: signed short _Accum.
Definition fill.h:19
void fill_rainbow_circular(CRGB *targetArray, int numToFill, u8 initialhue, bool reversed) FL_NO_EXCEPT
Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the...
Definition fill.cpp.hpp:54
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NO_EXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:10
void fill_rainbow(CRGB *targetArray, int numToFill, u8 initialhue, u8 deltahue) FL_NO_EXCEPT
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp.hpp:30
void fill_gradient_RGB(CRGB *leds, u16 startpos, CRGB startcolor, u16 endpos, CRGB endcolor) FL_NO_EXCEPT
Fill a range of LEDs with a smooth RGB gradient between two RGB colors.
Definition fill.cpp.hpp:108
fl::hsv8 CHSV
Definition chsv.h:11
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
u16 accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Definition stdint.h:181
Base definition for an LED controller.
Definition crgb.hpp:179
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38