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

◆ draw()

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

Implements fl::IAnimartrix2Viz.

Definition at line 111 of file module_experiment10.cpp.hpp.

111 {
112 using FP = fl::s16x16;
113
114 auto *e = ctx.mEngine.get();
115 e->get_ready();
116 mState.ensureCache(e);
117 const fl::i32 *fade_lut = fl::assume_aligned<16>(mState.fade_lut);
118 const fl::u8 *perm = PERLIN_NOISE;
119
120 e->timings.master_speed = 0.01;
121
122 float w = 1;
123
124 e->timings.ratio[0] = 0.01;
125 e->timings.ratio[1] = 0.011;
126 e->timings.ratio[2] = 0.013;
127 e->timings.ratio[3] = 0.33 * w;
128 e->timings.ratio[4] = 0.36 * w;
129 e->timings.ratio[5] = 0.38 * w;
130 e->timings.ratio[6] = 0.0003;
131
132 e->timings.offset[0] = 0;
133 e->timings.offset[1] = 100;
134 e->timings.offset[2] = 200;
135 e->timings.offset[3] = 300;
136 e->timings.offset[4] = 400;
137 e->timings.offset[5] = 500;
138 e->timings.offset[6] = 600;
139
140 e->calculate_oscillators(e->timings);
141
142 const int total_pixels = mState.count;
143 constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP::FRAC_BITS;
144 constexpr float r_factor = 1.5f;
145
146 const fl::i32 cx_raw = FP(e->animation.center_x).raw();
147 const fl::i32 cy_raw = FP(e->animation.center_y).raw();
148 const fl::i32 scale_xy_raw = FP(0.1f * 0.4f).raw(); // 0.1 * s
149
150 // Per-frame angle offsets for each pass
151 const fl::i32 angle_offset1_raw = FP(e->move.noise_angle[0] + e->move.noise_angle[6]).raw();
152 const fl::i32 angle_offset2_raw = FP(e->move.noise_angle[1] + e->move.noise_angle[6]).raw();
153 const fl::i32 angle_offset3_raw = FP(e->move.noise_angle[2] + e->move.noise_angle[6]).raw();
154
155 // Per-frame sinf arguments
156 const float radial3 = e->move.radial[3];
157 const float radial4 = e->move.radial[4];
158 const float radial5 = e->move.radial[5];
159
160 // Per-frame time hue offset
161 const fl::u8 a = e->getTime() / 100;
162
163 // Base params struct (shared across all 3 passes)
164 render_parameters_fp p = {};
165 p.scale_x_raw = scale_xy_raw;
166 p.scale_y_raw = scale_xy_raw;
167 p.scale_z_raw = 0;
168 p.z_raw = FP(5.0f).raw();
169 p.center_x_raw = cx_raw;
170 p.center_y_raw = cy_raw;
171 p.low_limit_raw = 0;
172 p.high_limit_raw = FP_ONE;
173
174 // Pass-specific per-frame constants
175 const fl::i32 oz1_raw = FP(10.0f * e->move.linear[0]).raw();
176 const fl::i32 oy1_raw = FP(-5.0f * r_factor * e->move.linear[0]).raw();
177 const fl::i32 ox1_raw = FP(10.0f).raw();
178
179 const fl::i32 oz2_raw = FP(0.1f * e->move.linear[1]).raw();
180 const fl::i32 oy2_raw = FP(-5.0f * r_factor * e->move.linear[1]).raw();
181 const fl::i32 ox2_raw = FP(100.0f).raw();
182
183 const fl::i32 oz3_raw = FP(0.1f * e->move.linear[2]).raw();
184 const fl::i32 oy3_raw = FP(-5.0f * r_factor * e->move.linear[2]).raw();
185 const fl::i32 ox3_raw = FP(1000.0f).raw();
186
187 fl::span<CRGB> leds = e->mCtx->leds;
188
189 for (int i = 0; i < total_pixels; i++) {
190 const fl::i32 theta_raw = mState.polar_theta_raw[i];
191 const fl::i32 dist_raw_i = mState.distance_raw[i];
192 // Convert distance to float once for the sinf calls
193 const float dist_f = FP::from_raw(dist_raw_i).to_float();
194
195 // Pass 1: dist = 3 + distance + 3*sin(0.25*distance - radial[3])
196 fl::i32 dist1_raw = FP(3.0f + dist_f + 3.0f * fl::sinf(0.25f * dist_f - radial3)).raw();
197 p.angle_raw = theta_raw + angle_offset1_raw;
198 p.dist_raw = dist1_raw;
199 p.offset_z_raw = oz1_raw;
200 p.offset_y_raw = oy1_raw;
201 p.offset_x_raw = ox1_raw;
202 fl::i32 show1 = render_value_fp(p, fade_lut, perm);
203
204 // Pass 2: dist = 4 + distance + 4*sin(0.24*distance - radial[4])
205 fl::i32 dist2_raw = FP(4.0f + dist_f + 4.0f * fl::sinf(0.24f * dist_f - radial4)).raw();
206 p.angle_raw = theta_raw + angle_offset2_raw;
207 p.dist_raw = dist2_raw;
208 p.offset_z_raw = oz2_raw;
209 p.offset_y_raw = oy2_raw;
210 p.offset_x_raw = ox2_raw;
211 fl::i32 show2 = render_value_fp(p, fade_lut, perm);
212
213 // Pass 3: dist = 5 + distance + 5*sin(0.23*distance - radial[5])
214 fl::i32 dist3_raw = FP(5.0f + dist_f + 5.0f * fl::sinf(0.23f * dist_f - radial5)).raw();
215 p.angle_raw = theta_raw + angle_offset3_raw;
216 p.dist_raw = dist3_raw;
217 p.offset_z_raw = oz3_raw;
218 p.offset_y_raw = oy3_raw;
219 p.offset_x_raw = ox3_raw;
220 fl::i32 show3 = render_value_fp(p, fade_lut, perm);
221
222 // Color: CHSV with hue = (a + show1 + show2) + show3
223 CRGB c = CRGB(CHSV(static_cast<fl::u8>((a + show1 + show2) + show3), 255, 255));
224 leds[mState.pixel_idx[i]] = c;
225 }
226}
CRGB leds[1]
constexpr i32 raw() const FL_NO_EXCEPT
Definition s16x16.h:62
fl::hsv8 CHSV
Definition chsv.h:11
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
float sinf(float value) FL_NO_EXCEPT
Definition math.h:360
static constexpr i32 FP_ONE

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::FP_ONE, 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::render_parameters_fp::scale_x_raw, fl::render_parameters_fp::scale_y_raw, fl::render_parameters_fp::scale_z_raw, fl::sinf(), and fl::render_parameters_fp::z_raw.

+ Here is the call graph for this function: