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

◆ draw()

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

Implements fl::IAnimartrix2Viz.

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

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

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::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::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: