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

◆ getPaletteIndex()

uint8_t getPaletteIndex ( uint32_t millis32,
int width,
int max_width,
int height,
int max_height,
uint32_t y_speed )

Definition at line 112 of file FireCylinder.h.

113 {
114 // This function calculates which color to use from our palette for each LED
115
116 // Get the scale factor from the UI slider
118
119 // Convert width position to an angle (0-255 represents 0-360 degrees)
120 // This maps our flat coordinate to a position on a cylinder
121 float xf = (float)width / (float)max_width; // Normalized position (0.0 to 1.0)
122 uint8_t x = (uint8_t)(xf * 255); // Convert to 0-255 range for trig functions
123
124 // Calculate the sine and cosine of this angle to get 3D coordinates on the cylinder
125 uint32_t cosx = cos8(x); // cos8 returns a value 0-255 representing cosine
126 uint32_t sinx = sin8(x); // sin8 returns a value 0-255 representing sine
127
128 // Apply scaling to the sine/cosine values
129 // This controls how "wide" the noise pattern is around the cylinder
130 float trig_scale = scale * scaleX.value();
131 cosx *= trig_scale;
132 sinx *= trig_scale;
133
134 // Calculate Y coordinate (vertical position) with speed offset for movement
136
137 // Calculate Z coordinate (time dimension) - controls how the pattern changes over time
138 uint16_t z = millis32 / invSpeedZ.as<uint16_t>();
139 FL_UNUSED(z); // Suppress unused variable warning
140
141 // Generate 16-bit Perlin noise using our 4D coordinates (x,y,z,t)
142 // The << 8 shifts values left by 8 bits (multiplies by 256) to use the full 16-bit range
143 // The last parameter (0) could be replaced with another time variable for more variation
144 uint16_t noise16 = inoise16(cosx << 8, sinx << 8, y << 8, 0);
145
146 // Convert 16-bit noise to 8-bit by taking the high byte
147 uint8_t noise_val = noise16 >> 8;
148
149 // Calculate how much to subtract based on vertical position (height)
150 // This creates the fade-out effect from bottom to top
151 // The formula maps height from 0 to max_height-1 to a value from 255 to 0
152 int8_t subtraction_factor = abs8(height - (max_height - 1)) * 255 /
153 (max_height - 1);
154
155 // Subtract the factor from the noise value (with underflow protection)
156 // qsub8 is a "saturating subtraction" - it won't go below 0
157 return qsub8(noise_val, subtraction_factor);
158}
int y
Definition simple.h:93
int x
Definition simple.h:92
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:93
fl::UISlider scaleX("ScaleX",.3, 0.1, 3,.01)
fl::UISlider invSpeedZ("Inverse SpeedZ", 20, 1, 100, 1)
fl::UISlider scaleXY("Scale", 8, 1, 100, 1)
fl::UISlider scale("Scale", 4,.1, 4,.1)
int y_speed
fl::u16 inoise16(fl::u32 x, fl::u32 y, fl::u32 z, fl::u32 t)
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u16 uint16_t
Definition s16x16x4.h:214
u8 u8 height
Definition blur.h:186
signed char int8_t
Definition s16x16x4.h:210
unsigned char uint8_t
Definition s16x16x4.h:209
#define FL_UNUSED(x)

References FL_UNUSED, inoise16(), invSpeedZ(), scale, scaleX(), scaleXY(), x, y, y_speed, and z.

Referenced by loop().

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