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

◆ noiseRingCRGB()

CRGB fl::noiseRingCRGB ( float angle,
u32 time,
float radius = 1.0f )

Generate CRGB noise for a ring pattern.

Samples three z-slices of 3D Perlin noise to create independent red, green, and blue components (direct RGB, not HSV conversion).

Parameters
anglePosition around the ring (radians, 0 to 2π)
timeAnimation time parameter
radiusNoise zoom level (level of detail). Larger values = coarser pattern, smaller = more detail (default 1.0)
Returns
CRGB color with 8-bit components

Definition at line 63 of file noise.cpp.hpp.

63 {
64 // Convert angle to cartesian coordinates
65 float x = fl::cosf(angle);
66 float y = fl::sinf(angle);
67
68 // Map sin/cos values from [-1, 1] to [0, 0xFFFF]
69 // This ensures positive values for uint32_t conversion
70 u32 nx = static_cast<u32>((x + 1.0f) * 0.5f * radius * 0xffff);
71 u32 ny = static_cast<u32>((y + 1.0f) * 0.5f * radius * 0xffff);
72
73 // Sample three different z-slices for R, G, B components (direct RGB)
74 // Using offsets 0x0, 0x10000, 0x20000 to separate them in noise space
75 u16 r16_raw = inoise16(nx, ny, time);
76 u16 g16_raw = inoise16(nx, ny, time + 0x10000);
77 u16 b16_raw = inoise16(nx, ny, time + 0x20000);
78
79 // Rescale from observed noise range to full 0-65535 range using global extents
80 u16 r16 = rescaleNoiseValue16(r16_raw);
81 u16 g16 = rescaleNoiseValue16(g16_raw);
82 u16 b16 = rescaleNoiseValue16(b16_raw);
83
84 // Scale down to 8-bit
85 u8 r = r16 >> 8;
86 u8 g = g16 >> 8;
87 u8 b = b16 >> 8;
88
89 return CRGB(r, g, b);
90}
fl::u16 inoise16(fl::u32 x, fl::u32 y, fl::u32 z, fl::u32 t)
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
FASTLED_FORCE_INLINE u16 rescaleNoiseValue16(u16 raw_value)
Rescale raw inoise16() output to full 16-bit range [0, 65535] Curries in the global NOISE16_EXTENT_MI...
Definition noise.cpp.hpp:21
fl::u64 time() FL_NOEXCEPT
Alias for millis64() - returns 64-bit millisecond time.
Definition chrono.h:346
float sinf(float value) FL_NOEXCEPT
Definition math.h:352
float cosf(float value) FL_NOEXCEPT
Definition math.h:358

References cosf(), inoise16(), rescaleNoiseValue16(), sinf(), time(), x, and y.

+ Here is the call graph for this function: