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

◆ drawAALine()

void fl::FlowFieldFP::drawAALine ( s16x16 x0,
s16x16 y0,
s16x16 x1,
s16x16 y1,
s16x16 t,
s16x16 colorShift )
private

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

616 {
617 int w = mState.width;
618 int h = mState.height;
619 s16x16 dx = x1 - x0;
620 s16x16 dy = y1 - y0;
621 s16x16 max_delta = fl::max(s16x16::abs(dx), s16x16::abs(dy));
622 int steps = fl::max(1, (max_delta * s16x16(3)).to_int());
623 s16x16 invSteps = s16x16(1) / s16x16(steps);
624
625 i32 *__restrict__ rp = mState.r.data();
626 i32 *__restrict__ gp = mState.g.data();
627 i32 *__restrict__ bp = mState.b.data();
628
629 // Precompute step increments (was recomputing from scratch each iteration)
630 s16x16 dx_step = dx * invSteps;
631 s16x16 dy_step = dy * invSteps;
632 s16x16 u = s16x16();
633 s16x16 px = x0;
634 s16x16 py = y0;
635
636 for (int i = 0; i <= steps; i++, u = u + invSteps, px = px + dx_step, py = py + dy_step) {
637 CRGB c = rainbow(t, colorShift, u);
638
639 int ix = s16x16::floor(px).to_int();
640 int iy = s16x16::floor(py).to_int();
641 s16x16 fx = s16x16::fract(px);
642 s16x16 fy = s16x16::fract(py);
643 constexpr s16x16 one(1.0f);
644 s16x16 inv_fx = one - fx;
645 s16x16 inv_fy = one - fy;
646
647 i32 weights[4] = {
648 (inv_fx * inv_fy).raw(),
649 (fx * inv_fy).raw(),
650 (inv_fx * fy).raw(),
651 (fx * fy).raw(),
652 };
653
654 // Pre-shift color values once per step
655 i32 cr_raw = static_cast<i32>(c.r) << 16;
656 i32 cg_raw = static_cast<i32>(c.g) << 16;
657 i32 cb_raw = static_cast<i32>(c.b) << 16;
658
659 int offX[4] = {0, 1, 0, 1};
660 int offY[4] = {0, 0, 1, 1};
661
662 for (int j = 0; j < 4; j++) {
663 int cx = ix + offX[j];
664 int cy = iy + offY[j];
665 if (cx < 0 || cx >= w || cy < 0 || cy >= h)
666 continue;
667 i32 wt_q16 = weights[j];
668 if (wt_q16 <= 0) continue;
669 int gi = cy * w + cx;
670 // Lerp: old + (new - old) * wt — 1 i64 mul per channel instead of 2
671 rp[gi] += static_cast<i32>((static_cast<i64>(cr_raw - rp[gi]) * wt_q16) >> 16);
672 gp[gi] += static_cast<i32>((static_cast<i64>(cg_raw - gp[gi]) * wt_q16) >> 16);
673 bp[gi] += static_cast<i32>((static_cast<i64>(cb_raw - bp[gi]) * wt_q16) >> 16);
674 }
675 }
676}
void rainbow()
fl::UISlider colorShift("Color Shift", 0.04f, 0.0f, 0.5f, 0.01f)
FlowFieldFPState mState
Definition flowfield.h:400
constexpr FASTLED_FORCE_INLINE s16x16 floor() const FL_NOEXCEPT
Definition s16x16.h:251
constexpr i32 to_int() const FL_NOEXCEPT
Definition s16x16.h:61
constexpr FASTLED_FORCE_INLINE s16x16 fract() const FL_NOEXCEPT
Definition s16x16.h:259
constexpr FASTLED_FORCE_INLINE s16x16 abs() const FL_NOEXCEPT
Definition s16x16.h:263
fl::UISlider steps("Steps", 100.0f, 1.0f, 200.0f, 1.0f)
fl::CRGB CRGB
Definition video.h:15
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
fl::i64 i64
Definition s16x16x4.h:222

References fl::s16x16::abs(), colorShift, fl::s16x16::floor(), fl::s16x16::fract(), fl::max(), mState, rainbow(), steps(), fl::t, and fl::s16x16::to_int().

Referenced by emitLissajousLine().

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