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

◆ fill_2dnoise8()

void fill_2dnoise8 ( CRGB * leds,
int width,
int height,
bool serpentine,
uint8_t octaves,
uint16_t x,
int xscale,
uint16_t y,
int yscale,
uint16_t time,
uint8_t hue_octaves,
uint16_t hue_x,
int hue_xscale,
uint16_t hue_y,
uint16_t hue_yscale,
uint16_t hue_time,
bool blend )

Fill an LED matrix with random colors, using 8-bit noise.

Parameters
ledspointer to LED array
widththe width of the LED matrix
heightthe height of the LED matrix
serpentinewhether the matrix is laid out in a serpentine pattern (alternating left/right directions per row)
octavesthe number of octaves to use for value (brightness) noise
xx-axis coordinate on noise map for value (brightness) noise
xscalethe scale (distance) between x points when filling in value (brightness) noise
yy-axis coordinate on noise map for value (brightness) noise
yscalethe scale (distance) between y points when filling in value (brightness) noise
timethe time position for the value (brightness) noise field
hue_octavesthe number of octaves to use for color hue noise
hue_xx-axis coordinate on noise map for color hue noise
hue_xscalethe scale (distance) between x points when filling in color hue noise
hue_yy-axis coordinate on noise map for color hue noise.
hue_yscalethe scale (distance) between y points when filling in color hue noise
hue_timethe time position for the color hue noise field
blendif true, will blend the newly generated LED values into the array. If false, will overwrite the array values directly.

Definition at line 879 of file noise.cpp.

881 {
882 const size_t array_size = (size_t)height * width;
883 if (array_size <= 0) return;
884 FASTLED_STACK_ARRAY(uint8_t, V, array_size);
885 FASTLED_STACK_ARRAY(uint8_t, H, array_size);
886
887 fl::memfill(V,0,height*width);
888 fl::memfill(H,0,height*width);
889
890 fill_raw_2dnoise8((uint8_t*)V,width,height,octaves,x,xscale,y,yscale,time);
891 fill_raw_2dnoise8((uint8_t*)H,width,height,hue_octaves,hue_x,hue_xscale,hue_y,hue_yscale,hue_time);
892
893 int w1 = width-1;
894 int h1 = height-1;
895 for(int i = 0; i < height; ++i) {
896 int wb = i*width;
897 for(int j = 0; j < width; ++j) {
898 CRGB led(CHSV(H[(h1-i)*width + (w1-j)], 255, V[i*width + j]));
899
900 int pos = j;
901 if(serpentine && (i & 0x1)) {
902 pos = w1-j;
903 }
904
905 if(blend) {
906 // Safer blending to avoid potential undefined behavior
907 CRGB temp = leds[wb+pos];
908 temp.nscale8(128); // Scale by 50%
909 led.nscale8(128);
910 leds[wb+pos] = temp + led;
911 } else {
912 leds[wb+pos] = led;
913 }
914 }
915 }
916}
CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
uint8_t pos
Definition Blur.ino:11
uint8_t hue_octaves
int yscale
uint8_t octaves
int xscale
uint32_t hue_time
#define FASTLED_STACK_ARRAY(TYPE, NAME, SIZE)
Definition array.h:185
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
void fill_raw_2dnoise8(uint8_t *pData, int width, int height, uint8_t octaves, q44 freq44, fract8 amplitude, int skip, uint16_t x, int16_t scalex, uint16_t y, int16_t scaley, uint16_t time)
Fill a 2D 8-bit buffer with noise, using inoise8()
Definition noise.cpp:713
void * memfill(void *ptr, int value, fl::size num)
Definition memfill.h:11
__SIZE_TYPE__ size_t
Definition cstddef.h:17
CRGB & nscale8(fl::u8 scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition hsv.h:15

References blend(), FASTLED_STACK_ARRAY, fill_raw_2dnoise8(), hue_octaves, hue_time, leds, fl::memfill(), CRGB::nscale8(), octaves, pos, x, xscale, y, and yscale.

+ Here is the call graph for this function: