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

◆ noiseSphereCRGB()

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

Generate CRGB noise for a sphere pattern.

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

Parameters
angleAzimuth angle around the sphere (radians, 0 to 2π)
phiPolar angle from the north pole (radians, 0 to π)
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 133 of file noise.cpp.hpp.

133 {
134 // Convert spherical coordinates to cartesian
135 // angle: azimuth (0 to 2π), phi: polar angle from north pole (0 to π)
136 // x = sin(phi) * cos(angle)
137 // y = sin(phi) * sin(angle)
138 // z = cos(phi)
139 float sin_phi = fl::sinf(phi);
140 float cos_phi = fl::cosf(phi);
141 float x = sin_phi * fl::cosf(angle);
142 float y = sin_phi * fl::sinf(angle);
143 float z = cos_phi;
144
145 // Map cartesian values from [-1, 1] to [0, 0xFFFF]
146 // This ensures positive values for uint32_t conversion
147 u32 nx = static_cast<u32>((x + 1.0f) * 0.5f * radius * 0xffff);
148 u32 ny = static_cast<u32>((y + 1.0f) * 0.5f * radius * 0xffff);
149 u32 nz = static_cast<u32>((z + 1.0f) * 0.5f * radius * 0xffff);
150
151 // Sample three different t-slices for R, G, B components (direct RGB)
152 // Using offsets 0x0, 0x10000, 0x20000 to separate them in noise space
153 u16 r16 = inoise16(nx, ny, nz, time);
154 u16 g16 = inoise16(nx, ny, nz, time + 0x10000);
155 u16 b16 = inoise16(nx, ny, nz, time + 0x20000);
156
157 u8 r = fl::int_scale<u16, u8>(r16);
158 u8 g = fl::int_scale<u16, u8>(g16);
159 u8 b = fl::int_scale<u16, u8>(b16);
160
161 return CRGB(r, g, b);
162}
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:93
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
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(), sinf(), time(), x, y, and z.

+ Here is the call graph for this function: