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

◆ fillFrameBufferNoise()

FL_OPTIMIZATION_LEVEL_O0_END void fillFrameBufferNoise ( )

Definition at line 434 of file curr.h.

434 {
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
490 // Map noise to color using palette (adapted from NoisePlusPalette)
491 uint8_t index = data;
492 uint8_t bri = data;
493
494 // Add color cycling if enabled - also derive from time
495 uint8_t ihue = 0;
496 if(colorLoop) {
497 ihue = (now / 100) % 256; // Derive hue from time instead of incrementing
498 index += ihue;
499 }
500
501 // Enhance brightness (from NoisePlusPalette example)
502 // if(bri > 127) {
503 // //bri = 255;
504 // } else {
505 // //bri = dim8_raw(bri * 2);
506 // }
507
508 // Get color from palette and set pixel
509 fl::CRGB color = ColorFromPalette(noisePalette, index, bri);
510
511 // Apply color boost using ease functions
512 fl::EaseType sat_ease = getEaseType(saturationFunction.value());
513 fl::EaseType lum_ease = getEaseType(luminanceFunction.value());
514 color = color.colorBoost(sat_ease, lum_ease);
515
516 frameBufferPtr->at(x, y) = color;
517 }
518 }
519}
int y
Definition simple.h:93
int x
Definition simple.h:92
fl::UIDropdown saturationFunction("Saturation Function", easeOptions)
fl::UIDropdown luminanceFunction("Luminance Function", easeOptions)
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
fl::UISlider noiseSpeed("Noise Speed", 4, 1, 100, 1)
fl::EaseType getEaseType(fl::string value)
Definition curr.h:129
uint8_t colorLoop
Definition curr.h:244
fl::CRGBPalette16 noisePalette
Definition curr.h:243
fl::UISlider noiseScale("Noise Scale", 100, 10, 200, 5)
fl::shared_ptr< fl::Grid< fl::CRGB > > frameBufferPtr
Definition curr.h:279
fl::u8 inoise8(fl::u16 x, fl::u16 y, fl::u16 z)
#define FL_PI
Definition math.h:26
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u16 uint16_t
Definition s16x16x4.h:214
u8 u8 height
Definition blur.h:186
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
u8 width
Definition blur.h:186
enable_if< is_fixed_point< T >::value, T >::type cos(T angle) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type sin(T angle) FL_NOEXCEPT
EaseType
Definition ease.h:27
unsigned char uint8_t
Definition s16x16x4.h:209
CRGB colorBoost(EaseType saturation_function=EaseType::EASE_NONE, EaseType luminance_function=EaseType::EASE_NONE) const FL_NOEXCEPT
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References fl::CRGB::colorBoost(), ColorFromPalette(), colorLoop, fl::cos(), FL_PI, frameBufferPtr, getEaseType(), inoise8(), luminanceFunction(), fl::millis(), noisePalette, noiseScale(), noiseSpeed(), saturationFunction(), fl::sin(), x, and y.

Referenced by drawNoise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: