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

◆ draw()

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

Implements fl::IAnimartrix2Viz.

Definition at line 292 of file chasing_spirals.cpp.hpp.

292 {
293 auto *e = ctx.mEngine.get();
294 e->get_ready();
295
296 // Perlin noise is periodic with period 256 at integer coordinates.
297 // scale_x = 0.1, so the effective period for offset_x is 256/0.1 = 2560.
298 // Reducing move.linear[i] modulo this period before use keeps float32
299 // coordinate arithmetic precise even at extreme uptime values.
300 // Without this, float32 loses per-pixel precision when adding a small
301 // per-pixel term (~0.1) to a large offset (e.g. 200,000), since float32
302 // ULP at that magnitude (~0.024) is coarser than the per-pixel step.
303 // This matches the reduction already applied in setupChasingSpiralFrame
304 // for the Q31 path, keeping both paths in agreement at all time values.
305 static constexpr float perlin_period = 2560.0f; // 256.0f / scale_x(0.1f)
306
307 e->timings.master_speed = 0.01;
308 e->timings.ratio[0] = 0.1;
309 e->timings.ratio[1] = 0.13;
310 e->timings.ratio[2] = 0.16;
311 e->timings.offset[1] = 10;
312 e->timings.offset[2] = 20;
313 e->timings.offset[3] = 30;
314 e->calculate_oscillators(e->timings);
315
316 for (int x = 0; x < e->num_x; x++) {
317 for (int y = 0; y < e->num_y; y++) {
318 e->animation.angle =
319 3 * e->polar_theta[x][y] + e->move.radial[0] -
320 e->distance[x][y] / 3;
321 e->animation.dist = e->distance[x][y];
322 e->animation.scale_z = 0.1;
323 e->animation.scale_y = 0.1;
324 e->animation.scale_x = 0.1;
325 e->animation.offset_x = fl::fmodf(e->move.linear[0], perlin_period);
326 e->animation.offset_y = 0;
327 e->animation.offset_z = 0;
328 e->animation.z = 0;
329 float show1 = e->render_value(e->animation);
330
331 e->animation.angle =
332 3 * e->polar_theta[x][y] + e->move.radial[1] -
333 e->distance[x][y] / 3;
334 e->animation.dist = e->distance[x][y];
335 e->animation.offset_x = fl::fmodf(e->move.linear[1], perlin_period);
336 float show2 = e->render_value(e->animation);
337
338 e->animation.angle =
339 3 * e->polar_theta[x][y] + e->move.radial[2] -
340 e->distance[x][y] / 3;
341 e->animation.dist = e->distance[x][y];
342 e->animation.offset_x = fl::fmodf(e->move.linear[2], perlin_period);
343 float show3 = e->render_value(e->animation);
344
345 float radius = e->radial_filter_radius;
346 float radial_filter = (radius - e->distance[x][y]) / radius;
347
348 e->pixel.red = 3 * show1 * radial_filter;
349 e->pixel.green = show2 * radial_filter / 2;
350 e->pixel.blue = show3 * radial_filter / 4;
351
352 e->pixel = e->rgb_sanity_check(e->pixel);
353 e->setPixelColorInternal(x, y, e->pixel);
354 }
355 }
356}
float fmodf(float x, float y) FL_NOEXCEPT
Definition math.h:336

References fl::fmodf(), fl::Context::mEngine, fl::x, and fl::y.

+ Here is the call graph for this function: