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

◆ draw()

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

Implements fl::IAnimartrix2Viz.

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

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

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::FL_NO_EXCEPT, fl::fmodf(), fl::FP_ONE, fl::g, fl::render_parameters_fp::high_limit_raw, leds, fl::render_parameters_fp::low_limit_raw, 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: