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

◆ drawAALine()

void fl::FlowFieldFloat::drawAALine ( float x0,
float y0,
float x1,
float y1,
float t,
float colorShift )
private

Definition at line 190 of file flowfield.cpp.hpp.

191 {
192 int w = (int)getWidth();
193 int h = (int)getHeight();
194 float dx = x1 - x0;
195 float dy = y1 - y0;
196 int steps = fl::max(1, (int)(fl::max(fabsf(dx), fabsf(dy)) * 3.0f));
197 float invSteps = 1.0f / (float)steps;
198
199 for (int i = 0; i <= steps; i++) {
200 float u = i * invSteps;
201 float px = x0 + dx * u;
202 float py = y0 + dy * u;
203 CRGB c = rainbow(t, colorShift, u);
204
205 int ix = (int)floorf(px);
206 int iy = (int)floorf(py);
207 float fx = px - ix;
208 float fy = py - iy;
209
210 float weights[4] = {
211 (1.0f - fx) * (1.0f - fy),
212 fx * (1.0f - fy),
213 (1.0f - fx) * fy,
214 fx * fy,
215 };
216 int offX[4] = {0, 1, 0, 1};
217 int offY[4] = {0, 0, 1, 1};
218
219 for (int j = 0; j < 4; j++) {
220 int cx = ix + offX[j];
221 int cy = iy + offY[j];
222 if (cx < 0 || cx >= w || cy < 0 || cy >= h)
223 continue;
224 float wt = weights[j];
225 if (wt <= 0.0f)
226 continue;
227 int gi = idx(cy, cx);
228 float inv = 1.0f - wt;
229 mR[gi] = mR[gi] * inv + c.r * wt;
230 mG[gi] = mG[gi] * inv + c.g * wt;
231 mB[gi] = mB[gi] * inv + c.b * wt;
232 }
233 }
234}
void rainbow()
fl::UISlider colorShift("Color Shift", 0.04f, 0.0f, 0.5f, 0.01f)
fl::vector< float > mB
Definition flowfield.h:346
fl::vector< float > mG
Definition flowfield.h:346
int idx(int y, int x) const FL_NO_EXCEPT
Definition flowfield.h:323
fl::vector< float > mR
Definition flowfield.h:346
u16 getWidth() const FL_NO_EXCEPT
Definition fx2d.h:25
u16 getHeight() const FL_NO_EXCEPT
Definition fx2d.h:24
fl::UISlider steps("Steps", 100.0f, 1.0f, 200.0f, 1.0f)
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
fl::CRGB CRGB
Definition video.h:18
float fabsf(float value) FL_NO_EXCEPT
Definition math.h:516
float floorf(float value) FL_NO_EXCEPT
Definition math.h:312

References colorShift, fl::fabsf(), fl::FL_NO_EXCEPT, fl::floorf(), fl::Fx2d::getHeight(), fl::Fx2d::getWidth(), idx(), fl::max(), mB, mG, mR, rainbow(), steps(), and fl::t.

Referenced by emitLissajousLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: