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

◆ fillFrameBufferNoise()

FL_OPTIMIZATION_LEVEL_O0_END void fillFrameBufferNoise ( )

Definition at line 446 of file curr.h.

446 {
447 // Get current UI values
448 uint8_t noise_scale = noiseScale.value();
449 uint8_t noise_speed = noiseSpeed.value();
450
451 // Derive noise coordinates from current time instead of forward iteration
452 uint32_t now = millis();
453 uint16_t noise_z = now * noise_speed / 10; // Primary time dimension
454 uint16_t noise_x = now * noise_speed / 80; // Slow drift in x
455 uint16_t noise_y = now * noise_speed / 160; // Even slower drift in y (opposite direction)
456
457 int width = frameBufferPtr->width();
458 int height = frameBufferPtr->height();
459
460 // Data smoothing for low speeds (from NoisePlusPalette example)
461 uint8_t dataSmoothing = 0;
462 if(noise_speed < 50) {
463 dataSmoothing = 200 - (noise_speed * 4);
464 }
465
466 // Generate noise for each pixel in the frame buffer using cylindrical mapping
467 for(int x = 0; x < width; x++) {
468 for(int y = 0; y < height; y++) {
469 // Convert rectangular coordinates to cylindrical coordinates
470 // Map x to angle (0 to 2*PI), y remains as height
471 float angle = (float(x) / float(width)) * 2.0f * PI;
472
473 // Convert cylindrical coordinates to cartesian for noise sampling
474 // Use the noise_scale to control the cylinder size in noise space
475 float cylinder_radius = noise_scale; // Use the existing noise_scale parameter
476
477 // Calculate cartesian coordinates on the cylinder surface
478 float noise_x_cyl = cos(angle) * cylinder_radius;
479 float noise_y_cyl = sin(angle) * cylinder_radius;
480 float noise_z_height = float(y) * noise_scale; // Height component
481
482 // Apply time-based offsets
483 int xoffset = int(noise_x_cyl) + noise_x;
484 int yoffset = int(noise_y_cyl) + noise_y;
485 int zoffset = int(noise_z_height) + noise_z;
486
487 // Generate 8-bit noise value using 3D Perlin noise with cylindrical coordinates
488 uint8_t data = inoise8(xoffset, yoffset, zoffset);
489
490 // Expand the range from ~16-238 to 0-255 (from NoisePlusPalette)
491 data = qsub8(data, 16);
492 data = qadd8(data, scale8(data, 39));
493
494 // Apply data smoothing if enabled
495 if(dataSmoothing) {
496 CRGB oldColor = frameBufferPtr->at(x, y);
497 uint8_t olddata = (oldColor.r + oldColor.g + oldColor.b) / 3; // Simple brightness extraction
498 uint8_t newdata = scale8(olddata, dataSmoothing) + scale8(data, 256 - dataSmoothing);
499 data = newdata;
500 }
501
502 // Map noise to color using palette (adapted from NoisePlusPalette)
503 uint8_t index = data;
504 uint8_t bri = data;
505
506 // Add color cycling if enabled - also derive from time
507 uint8_t ihue = 0;
508 if(colorLoop) {
509 ihue = (now / 100) % 256; // Derive hue from time instead of incrementing
510 index += ihue;
511 }
512
513 // Enhance brightness (from NoisePlusPalette example)
514 // if(bri > 127) {
515 // //bri = 255;
516 // } else {
517 // //bri = dim8_raw(bri * 2);
518 // }
519
520 // Get color from palette and set pixel
521 CRGB color = ColorFromPalette(noisePalette, index, bri);
522
523 // Apply color boost using ease functions
524 EaseType sat_ease = getEaseType(saturationFunction.value());
525 EaseType lum_ease = getEaseType(luminanceFunction.value());
526 color = color.colorBoost(sat_ease, lum_ease);
527
528 frameBufferPtr->at(x, y) = color;
529 }
530 }
531}
int y
Definition simple.h:93
int x
Definition simple.h:92
UIDropdown luminanceFunction("Luminance Function", easeOptions)
UIDropdown saturationFunction("Saturation Function", easeOptions)
uint8_t colorLoop
Definition curr.h:256
UISlider noiseScale("Noise Scale", 100, 10, 200, 5)
fl::shared_ptr< Grid< CRGB > > frameBufferPtr
Definition curr.h:291
UISlider noiseSpeed("Noise Speed", 4, 1, 100, 1)
CRGBPalette16 noisePalette
Definition curr.h:255
EaseType getEaseType(fl::string value)
Definition curr.h:142
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
Definition math8.h:40
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:112
uint8_t inoise8(uint16_t x, uint16_t y, uint16_t z)
8-Bit, fixed point implementation of Perlin's noise.
Definition noise.cpp:570
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:44
#define PI
Definition math_macros.h:89
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
EaseType
Definition ease.h:21
CRGB colorBoost(fl::EaseType saturation_function=fl::EASE_NONE, fl::EaseType luminance_function=fl::EASE_NONE) const
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86

References CRGB::colorBoost(), fl::ColorFromPalette(), colorLoop, frameBufferPtr, getEaseType(), inoise8(), luminanceFunction(), noisePalette, noiseScale(), noiseSpeed(), PI, qadd8(), qsub8(), saturationFunction(), scale8(), x, and y.

Referenced by drawNoise().

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