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

◆ draw()

void fl::Center_Field_FP::draw ( Context & ctx)
overridevirtual

Implements fl::IAnimartrix2Viz.

Definition at line 67 of file center_field.cpp.hpp.

67 {
68 using FP = fl::s16x16;
69
70 auto *e = ctx.mEngine.get();
71 e->get_ready();
72
73 // Same timing setup as float
74 e->timings.master_speed = 0.01;
75 e->timings.ratio[0] = 1;
76 e->timings.ratio[1] = 1.1;
77 e->timings.ratio[2] = 1.2;
78 e->timings.offset[1] = 100;
79 e->timings.offset[2] = 200;
80 e->timings.offset[3] = 300;
81 e->calculate_oscillators(e->timings);
82
83 // Build/update per-pixel geometry cache
84 mState.ensureCache(e);
85
86 const int total_pixels = mState.count;
87 const fl::i32 *fade_lut = fl::assume_aligned<16>(mState.fade_lut);
88 const fl::u8 *perm = PERLIN_NOISE;
89
90 // Per-frame constants converted to s16x16
91 constexpr FP scale_xy(0.07f);
92 const FP center_x_fp(e->animation.center_x);
93 const FP center_y_fp(e->animation.center_y);
94
95 // Period reduction: Perlin noise is periodic with period 256 at integer
96 // coordinates. With scale_y = 0.07, the effective period for offset_y is
97 // 256 / 0.07 ≈ 3657.14. Reducing modulo this period prevents s16x16
98 // overflow and maintains precision at high time values.
99 constexpr float perlin_period = 3657.14285714f; // 256.0f / 0.07f
100 const FP offset_y_fp(fl::fmodf(e->move.linear[0], perlin_period));
101 constexpr FP five(5.0f);
102 constexpr FP four(4.0f);
103 const fl::i32 scale_xy_raw = scale_xy.raw();
104 const fl::i32 cx_raw = center_x_fp.raw();
105 const fl::i32 cy_raw = center_y_fp.raw();
106 const fl::i32 oy_raw = offset_y_fp.raw();
107 const fl::i32 five_raw = five.raw();
108 const fl::i32 four_raw = four.raw();
109
110 // low_limit=0, high_limit=1 (default render_parameters)
111 constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP::FRAC_BITS;
112
113 render_parameters_fp p = {};
114 p.scale_x_raw = scale_xy_raw;
115 p.scale_y_raw = scale_xy_raw;
116 p.scale_z_raw = FP(0.1f).raw();
117 p.offset_x_raw = 0;
118 p.offset_y_raw = oy_raw;
119 p.offset_z_raw = 0;
120 p.z_raw = 0;
121 p.center_x_raw = cx_raw;
122 p.center_y_raw = cy_raw;
123 p.low_limit_raw = 0;
124 p.high_limit_raw = FP_ONE;
125
126 fl::span<CRGB> leds = e->mCtx->leds;
127
128 for (int i = 0; i < total_pixels; i++) {
129 const fl::i32 theta_raw = mState.polar_theta_raw[i];
130 const fl::i32 sqrt_dist_raw = mState.sqrt_distance_raw[i];
131
132 // Pass 1: dist = 5 * sqrt(distance)
133 fl::i32 dist1_raw = static_cast<fl::i32>(
134 (static_cast<fl::i64>(five_raw) * sqrt_dist_raw) >> FP::FRAC_BITS);
135 p.angle_raw = theta_raw;
136 p.dist_raw = dist1_raw;
137 fl::i32 show1 = render_value_fp(p, fade_lut, perm);
138
139 // Pass 2: dist = 4 * sqrt(distance)
140 fl::i32 dist2_raw = static_cast<fl::i32>(
141 (static_cast<fl::i64>(four_raw) * sqrt_dist_raw) >> FP::FRAC_BITS);
142 p.dist_raw = dist2_raw;
143 fl::i32 show2 = render_value_fp(p, fade_lut, perm);
144
145 // pixel.red = show1, pixel.green = show2, pixel.blue = 0
146 fl::i32 r = show1;
147 fl::i32 g = show2;
148 fl::i32 b = 0;
149 rgb_sanity_check_fp(r, g, b);
150
151 leds[mState.pixel_idx[i]] = CRGB(
152 static_cast<fl::u8>(r),
153 static_cast<fl::u8>(g),
154 static_cast<fl::u8>(b));
155 }
156}
fl::CRGB leds[NUM_LEDS]
constexpr i32 raw() const FL_NOEXCEPT
Definition s16x16.h:60
unsigned char u8
Definition s16x16x4.h:132
T * assume_aligned(T *ptr) FL_NOEXCEPT
Definition s16x16x4.h:126
fl::CRGB CRGB
Definition video.h:15
static constexpr i32 FP_ONE
FASTLED_FORCE_INLINE void rgb_sanity_check_fp(fl::i32 &r, fl::i32 &g, fl::i32 &b)
FASTLED_FORCE_INLINE fl::i32 render_value_fp(const render_parameters_fp &p, const fl::i32 *fade_lut, const fl::u8 *perm)
fl::i64 i64
Definition s16x16x4.h:222
float fmodf(float x, float y) FL_NOEXCEPT
Definition math.h:336

References fl::render_parameters_fp::angle_raw, fl::fl::assume_aligned(), fl::render_parameters_fp::center_x_raw, fl::render_parameters_fp::center_y_raw, fl::render_parameters_fp::dist_raw, fl::fmodf(), fl::FP_ONE, fl::render_parameters_fp::high_limit_raw, leds, fl::render_parameters_fp::low_limit_raw, fl::Context::mEngine, mState, fl::render_parameters_fp::offset_x_raw, fl::render_parameters_fp::offset_y_raw, fl::render_parameters_fp::offset_z_raw, fl::s16x16::raw(), fl::render_value_fp(), fl::rgb_sanity_check_fp(), fl::render_parameters_fp::scale_x_raw, fl::render_parameters_fp::scale_y_raw, fl::render_parameters_fp::scale_z_raw, and fl::render_parameters_fp::z_raw.

+ Here is the call graph for this function: