MCPcopy Create free account
hub / github.com/FastLED/FastLED / fillFrameBufferNoise

Function fillFrameBufferNoise

examples/FestivalStick/curr.h:432–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430 }
431}
432FL_OPTIMIZATION_LEVEL_O0_END
433
434void fillFrameBufferNoise() {
435 // Get current UI values
436 uint8_t noise_scale = noiseScale.value();
437 uint8_t noise_speed = noiseSpeed.value();
438
439 // Derive noise coordinates from current time instead of forward iteration
440 uint32_t now = fl::millis();
441 uint16_t noise_z = now * noise_speed / 10; // Primary time dimension
442 uint16_t noise_x = now * noise_speed / 80; // Slow drift in x
443 uint16_t noise_y = now * noise_speed / 160; // Even slower drift in y (opposite direction)
444
445 int width = frameBufferPtr->width();
446 int height = frameBufferPtr->height();
447
448 // Data smoothing for low speeds (from NoisePlusPalette example)
449 uint8_t dataSmoothing = 0;
450 if(noise_speed < 50) {
451 dataSmoothing = 200 - (noise_speed * 4);
452 }
453
454 // Generate noise for each pixel in the frame buffer using cylindrical mapping
455 for(int x = 0; x < width; x++) {
456 for(int y = 0; y < height; y++) {
457 // Convert rectangular coordinates to cylindrical coordinates
458 // Map x to angle (0 to 2*FL_PI), y remains as height
459 float angle = (float(x) / float(width)) * 2.0f * FL_PI;
460
461 // Convert cylindrical coordinates to cartesian for noise sampling
462 // Use the noise_scale to control the cylinder size in noise space
463 float cylinder_radius = noise_scale; // Use the existing noise_scale parameter
464
465 // Calculate cartesian coordinates on the cylinder surface
466 float noise_x_cyl = fl::cos(angle) * cylinder_radius;
467 float noise_y_cyl = fl::sin(angle) * cylinder_radius;
468 float noise_z_height = float(y) * noise_scale; // Height component
469
470 // Apply time-based offsets
471 int xoffset = int(noise_x_cyl) + noise_x;
472 int yoffset = int(noise_y_cyl) + noise_y;
473 int zoffset = int(noise_z_height) + noise_z;
474
475 // Generate 8-bit noise value using 3D Perlin noise with cylindrical coordinates
476 uint8_t data = inoise8(xoffset, yoffset, zoffset);
477
478 // Expand the range from ~16-238 to 0-255 (from NoisePlusPalette)
479 data = qsub8(data, 16);
480 data = qadd8(data, scale8(data, 39));
481
482 // Apply data smoothing if enabled
483 if(dataSmoothing) {
484 fl::CRGB oldColor = frameBufferPtr->at(x, y);
485 uint8_t olddata = (oldColor.r + oldColor.g + oldColor.b) / 3; // Simple brightness extraction
486 uint8_t newdata = scale8(olddata, dataSmoothing) + scale8(data, 256 - dataSmoothing);
487 data = newdata;
488 }
489

Callers 1

drawNoiseFunction · 0.85

Calls 12

inoise8Function · 0.85
ColorFromPaletteFunction · 0.85
getEaseTypeFunction · 0.70
millisFunction · 0.50
cosFunction · 0.50
sinFunction · 0.50
scale8Function · 0.50
valueMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
atMethod · 0.45
colorBoostMethod · 0.45

Tested by

no test coverage detected