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

◆ getPaletteIndex()

uint8_t getPaletteIndex ( uint32_t millis32,
int i,
int j,
uint32_t y_speed )

Definition at line 115 of file FireMatrix.h.

115 {
116 // This function calculates which color to use from our palette for each LED
117
118 // Get the scale factor from the UI slider (controls the "size" of the fire)
119 uint16_t scale = scaleXY.as<uint16_t>();
120
121 // Calculate 3D coordinates for the Perlin noise function:
122 uint16_t x = i * scale; // X position (horizontal in matrix)
123 uint32_t y = j * scale + y_speed; // Y position (vertical) + movement offset
124 uint16_t z = millis32 / invSpeedZ.as<uint16_t>(); // Z position (time dimension)
125
126 // Generate 16-bit Perlin noise value using these coordinates
127 // The << 8 shifts values left by 8 bits (multiplies by 256) to use the full 16-bit range
128 uint16_t noise16 = inoise16(x << 8, y << 8, z << 8);
129
130 // Convert 16-bit noise to 8-bit by taking the high byte (>> 8 shifts right by 8 bits)
131 uint8_t noise_val = noise16 >> 8;
132
133 // Calculate how much to subtract based on vertical position (j)
134 // This creates the fade-out effect from bottom to top
135 // abs8() ensures we get a positive value
136 // The formula maps j from 0 to HEIGHT-1 to a value from 255 to 0
137 int8_t subtraction_factor = abs8(j - (HEIGHT - 1)) * 255 / (HEIGHT - 1);
138
139 // Subtract the factor from the noise value (with underflow protection)
140 // qsub8 is a "saturating subtraction" - it won't go below 0
141 return qsub8(noise_val, subtraction_factor);
142}
#define HEIGHT
Definition Blur2d.ino:10
uint32_t z[NUM_LAYERS]
Definition Fire2023.ino:84
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
UISlider scaleXY("Scale", 8, 1, 100, 1)
UISlider invSpeedZ("Inverse SpeedZ", 20, 1, 100, 1)
int y_speed
uint16_t scale
Definition funky.cpp:83
LIB8STATIC_ALWAYS_INLINE int8_t abs8(int8_t i)
Take the absolute value of a signed 8-bit uint8_t.
Definition math8.h:500
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:103
uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z, uint32_t t)
16-bit, fixed point implementation of Perlin's noise.
Definition noise.cpp:440

References abs8(), HEIGHT, inoise16(), invSpeedZ(), qsub8(), scale, 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: