FastLED 3.10.8
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 134 of file noise.cpp.hpp.

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

References cosf(), FL_NO_EXCEPT, g, inoise16(), sinf(), time(), x, y, and z.

+ Here is the call graph for this function: