FastLED 3.9.15
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages

◆ draw()

void draw ( uint32_t now)

Definition at line 73 of file FxNoiseRing.ino.

73 {
74 double angle_offset = double(now) / 32000.0 * 2 * M_PI;
75 now = (now << timeBitshift.as<int>()) * timescale.as<double>();
76 // go in circular formation and set the leds
77 for (int i = 0; i < NUM_LEDS; i++) {
78 // Sorry this is a little convoluted but we are applying noise
79 // in the 16-bit space and then mapping it back to 8-bit space.
80 // All the constants were experimentally determined.
81 float angle = i * 2 * M_PI / NUM_LEDS + angle_offset;
82 float x = cos(angle);
83 float y = sin(angle);
84 x *= 0xffff * scale.as<double>();
85 y *= 0xffff * scale.as<double>();
86 uint16_t noise = inoise16(x, y, now);
87 uint16_t noise2 = inoise16(x, y, 0xfff + now);
88 uint16_t noise3 = inoise16(x, y, 0xffff + now);
89 noise3 = noise3 >> 8;
90 int16_t noise4 = map(noise3, 0, 255, -64, 255);
91 if (noise4 < 0) { // Clamp negative values to 0.
92 noise4 = 0;
93 }
94 // Shift back to 8-bit space.
95 leds[i] = CHSV(noise >> 8, MAX(128, noise2 >> 8), noise4);
96 }
97}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
UISlider scale("Scale", 1.0f, 0.0f, 1.0f, 0.01f)
uint8_t noise[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:88
uint8_t noise2[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:89
UISlider timescale("Time Scale", 1,.1, 10,.1)
UISlider timeBitshift("Time Bitshift", 5, 0, 16, 1)
uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z, uint32_t t)
16-bit, fixed point implementation of Perlin's noise.
Definition noise.cpp:440
#define M_PI
Definition math_macros.h:67
#define MAX(a, b)
Definition math_macros.h:11
long map(long x, long in_min, long in_max, long out_min, long out_max)
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16

References inoise16(), leds, M_PI, MAX, noise, noise2, NUM_LEDS, scale, timeBitshift, timescale, x, and y.

Referenced by loop().

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