FastLED 3.10.8
Loading...
Searching...
No Matches

◆ noiseCylinderCRGB()

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

Generate CRGB noise for a cylinder pattern.

Samples three z-slices of 3D Perlin noise to create independent red, green, and blue components (direct RGB, not HSV conversion). Maps the angle around the circumference using sin/cos, and samples height directly.

Parameters
anglePosition around the cylinder (radians, 0 to 2π)
heightVertical position on the cylinder
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 209 of file noise.cpp.hpp.

209 {
210 // Convert cylindrical coordinates to cartesian
211 // angle: azimuth around cylinder (0 to 2π)
212 // height: vertical position (used directly)
213 // x = cos(angle)
214 // y = sin(angle)
215 // z = height
216 float x = fl::cosf(angle);
217 float y = fl::sinf(angle);
218
219 // Map sin/cos values from [-1, 1] to [0, 0xFFFF]
220 // This ensures positive values for uint32_t conversion
221 u32 nx = static_cast<u32>((x + 1.0f) * 0.5f * radius * 0xffff);
222 u32 ny = static_cast<u32>((y + 1.0f) * 0.5f * radius * 0xffff);
223 u32 nz = static_cast<u32>(height * radius * 0xffff);
224
225 // Sample three different t-slices for R, G, B components (direct RGB)
226 // Using offsets 0x0, 0x10000, 0x20000 to separate them in noise space
227 u16 r16_raw = inoise16(nx, ny, nz, time);
228 u16 g16_raw = inoise16(nx, ny, nz, time + 0x10000);
229 u16 b16_raw = inoise16(nx, ny, nz, time + 0x20000);
230
231 // Rescale from observed noise range to full 0-65535 range using global extents
232 u16 r16 = rescaleNoiseValue16(r16_raw);
233 u16 g16 = rescaleNoiseValue16(g16_raw);
234 u16 b16 = rescaleNoiseValue16(b16_raw);
235
236 // Scale down to 8-bit
237 u8 r = fl::int_scale<u16, u8>(r16);
238 u8 g = fl::int_scale<u16, u8>(g16);
239 u8 b = fl::int_scale<u16, u8>(b16);
240
241 return CRGB(r, g, b);
242}
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
u8 u8 height
Definition blur.h:186
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
FASTLED_FORCE_INLINE u16 rescaleNoiseValue16(u16 raw_value) FL_NO_EXCEPT
Rescale raw inoise16() output to full 16-bit range [0, 65535] Curries in the global NOISE16_EXTENT_MI...
Definition noise.cpp.hpp:22
InputGamut g
Definition rgbw.h:125
float cosf(float value) FL_NO_EXCEPT
Definition math.h:366

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

+ Here is the call graph for this function: