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

◆ Fire2023()

void Fire2023 ( uint32_t now)

Definition at line 139 of file Fire2023.h.

139 {
140 // some changing values
141 // these values are produced by perlin noise to add randomness and smooth transitions
142 uint16_t ctrl1 = inoise16(11 * now, 0, 0);
143 uint16_t ctrl2 = inoise16(13 * now, 100000, 100000);
144 uint16_t ctrl = ((ctrl1 + ctrl2) >> 1);
145
146 // parameters for the fire heat map
147 x[FIRENOISE] = 3 * ctrl * FIRESPEED;
148 y[FIRENOISE] = 20 * now * FIRESPEED;
149 z[FIRENOISE] = 5 * now * FIRESPEED;
152
153 //calculate the perlin noise data for the fire
154 for (uint8_t x_count = 0; x_count < WIDTH; x_count++) {
155 uint32_t xoffset = scale_x[FIRENOISE] * (x_count - CentreX);
156 for (uint8_t y_count = 0; y_count < HEIGHT; y_count++) {
157 uint32_t yoffset = scale_y[FIRENOISE] * (y_count - CentreY);
158 uint16_t data = ((inoise16(x[FIRENOISE] + xoffset, y[FIRENOISE] + yoffset, z[FIRENOISE])) + 1);
159 noise[FIRENOISE][x_count][y_count] = data >> 8;
160 }
161 }
162
163 // parameters for the smoke map
164 x[SMOKENOISE] = 3 * ctrl * SMOKESPEED;
165 y[SMOKENOISE] = 20 * now * SMOKESPEED;
166 z[SMOKENOISE] = 5 * now * SMOKESPEED;
169
170 //calculate the perlin noise data for the smoke
171 for (uint8_t x_count = 0; x_count < WIDTH; x_count++) {
172 uint32_t xoffset = scale_x[SMOKENOISE] * (x_count - CentreX);
173 for (uint8_t y_count = 0; y_count < HEIGHT; y_count++) {
174 uint32_t yoffset = scale_y[SMOKENOISE] * (y_count - CentreY);
175 uint16_t data = ((inoise16(x[SMOKENOISE] + xoffset, y[SMOKENOISE] + yoffset, z[SMOKENOISE])) + 1);
176 noise[SMOKENOISE][x_count][y_count] = data / SMOKENOISE_DIMMER;
177 }
178 }
179
180 //copy everything one line up
181 for (uint8_t y = 0; y < HEIGHT - 1; y++) {
182 for (uint8_t x = 0; x < WIDTH; x++) {
183 heat[XY(x, y)] = heat[XY(x, y + 1)];
184 }
185 }
186
187 // draw lowest line - seed the fire where it is brightest and hottest
188 for (uint8_t x = 0; x < WIDTH; x++) {
190 //if (heat[XY(x, HEIGHT-1)] < 200) heat[XY(x, HEIGHT-1)] = 150;
191 }
192
193 // dim the flames based on FIRENOISE noise.
194 // if the FIRENOISE noise is strong, the led goes out fast
195 // if the FIRENOISE noise is weak, the led stays on stronger.
196 // once the heat is gone, it stays dark.
197 for (uint8_t y = 0; y < HEIGHT - 1; y++) {
198 for (uint8_t x = 0; x < WIDTH; x++) {
199 uint8_t dim = noise[FIRENOISE][x][y];
200 // high value in FLAMEHEIGHT = less dimming = high flames
201 dim = dim / FLAMEHEIGHT;
202 dim = 255 - dim;
203 heat[XY(x, y)] = scale8(heat[XY(x, y)] , dim);
204
205 // map the colors based on heatmap
206 // use the heat map to set the color of the LED from the "hot" palette
207 // whichpalette position brightness blend or not
208 leds[XY(x, y)] = ColorFromPalette(hotPalette, heat[XY(x, y)], heat[XY(x, y)], LINEARBLEND);
209
210 // dim the result based on SMOKENOISE noise
211 // this is not saved in the heat map - the flame may dim away and come back
212 // next iteration.
213 leds[XY(x, y)].nscale8(noise[SMOKENOISE][x][y]);
214
215 }
216 }
217}
CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
#define SMOKENOISE
Definition Fire2023.h:91
uint8_t noise[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.h:98
#define CentreX
Definition Fire2023.h:42
#define FLAMEHEIGHT
Definition Fire2023.h:54
#define SMOKENOISESCALE
Definition Fire2023.h:65
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:94
uint8_t heat[NUM_LEDS]
Definition Fire2023.h:101
CRGBPalette32 hotPalette
Definition Fire2023.h:81
#define SMOKESPEED
Definition Fire2023.h:63
uint32_t scale_y[NUM_LAYERS]
Definition Fire2023.h:96
#define FIRENOISE
Definition Fire2023.h:90
#define FIRENOISESCALE
Definition Fire2023.h:55
#define SMOKENOISE_DIMMER
Definition Fire2023.h:64
#define FIRESPEED
Definition Fire2023.h:53
#define CentreY
Definition Fire2023.h:43
uint32_t scale_x[NUM_LAYERS]
Definition Fire2023.h:95
#define WIDTH
Definition advanced.h:36
#define HEIGHT
Definition advanced.h:37
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:420
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:44
fl::u16 XY(fl::u8 x, fl::u8 y)
Definition blur.cpp:22
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)

References CentreX, CentreY, fl::ColorFromPalette(), FIRENOISE, FIRENOISESCALE, FIRESPEED, FLAMEHEIGHT, heat, HEIGHT, hotPalette, inoise16(), leds, noise, scale8(), scale_x, scale_y, SMOKENOISE, SMOKENOISE_DIMMER, SMOKENOISESCALE, SMOKESPEED, WIDTH, x, fl::XY(), y, and z.

Referenced by loop().

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