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

◆ Fire2023()

void Fire2023 ( uint32_t now)

Definition at line 138 of file Fire2023.h.

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

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

Referenced by loop().

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