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

◆ Fire2023()

void Fire2023 ( uint32_t now)

Definition at line 127 of file Fire2023.ino.

127 {
128 // some changing values
129 // these values are produced by perlin noise to add randomness and smooth transitions
130 uint16_t ctrl1 = inoise16(11 * now, 0, 0);
131 uint16_t ctrl2 = inoise16(13 * now, 100000, 100000);
132 uint16_t ctrl = ((ctrl1 + ctrl2) >> 1);
133
134 // parameters for the fire heat map
135 x[FIRENOISE] = 3 * ctrl * FIRESPEED;
136 y[FIRENOISE] = 20 * now * FIRESPEED;
137 z[FIRENOISE] = 5 * now * FIRESPEED;
140
141 //calculate the perlin noise data for the fire
142 for (uint8_t x_count = 0; x_count < WIDTH; x_count++) {
143 uint32_t xoffset = scale_x[FIRENOISE] * (x_count - CentreX);
144 for (uint8_t y_count = 0; y_count < HEIGHT; y_count++) {
145 uint32_t yoffset = scale_y[FIRENOISE] * (y_count - CentreY);
146 uint16_t data = ((inoise16(x[FIRENOISE] + xoffset, y[FIRENOISE] + yoffset, z[FIRENOISE])) + 1);
147 noise[FIRENOISE][x_count][y_count] = data >> 8;
148 }
149 }
150
151 // parameters for the smoke map
152 x[SMOKENOISE] = 3 * ctrl * SMOKESPEED;
153 y[SMOKENOISE] = 20 * now * SMOKESPEED;
154 z[SMOKENOISE] = 5 * now * SMOKESPEED;
157
158 //calculate the perlin noise data for the smoke
159 for (uint8_t x_count = 0; x_count < WIDTH; x_count++) {
160 uint32_t xoffset = scale_x[SMOKENOISE] * (x_count - CentreX);
161 for (uint8_t y_count = 0; y_count < HEIGHT; y_count++) {
162 uint32_t yoffset = scale_y[SMOKENOISE] * (y_count - CentreY);
163 uint16_t data = ((inoise16(x[SMOKENOISE] + xoffset, y[SMOKENOISE] + yoffset, z[SMOKENOISE])) + 1);
164 noise[SMOKENOISE][x_count][y_count] = data / SMOKENOISE_DIMMER;
165 }
166 }
167
168 //copy everything one line up
169 for (uint8_t y = 0; y < HEIGHT - 1; y++) {
170 for (uint8_t x = 0; x < WIDTH; x++) {
171 heat[XY(x, y)] = heat[XY(x, y + 1)];
172 }
173 }
174
175 // draw lowest line - seed the fire where it is brightest and hottest
176 for (uint8_t x = 0; x < WIDTH; x++) {
178 //if (heat[XY(x, HEIGHT-1)] < 200) heat[XY(x, HEIGHT-1)] = 150;
179 }
180
181 // dim the flames based on FIRENOISE noise.
182 // if the FIRENOISE noise is strong, the led goes out fast
183 // if the FIRENOISE noise is weak, the led stays on stronger.
184 // once the heat is gone, it stays dark.
185 for (uint8_t y = 0; y < HEIGHT - 1; y++) {
186 for (uint8_t x = 0; x < WIDTH; x++) {
187 uint8_t dim = noise[FIRENOISE][x][y];
188 // high value in FLAMEHEIGHT = less dimming = high flames
189 dim = dim / FLAMEHEIGHT;
190 dim = 255 - dim;
191 heat[XY(x, y)] = scale8(heat[XY(x, y)] , dim);
192
193 // map the colors based on heatmap
194 // use the heat map to set the color of the LED from the "hot" palette
195 // whichpalette position brightness blend or not
197
198 // dim the result based on SMOKENOISE noise
199 // this is not saved in the heat map - the flame may dim away and come back
200 // next iteration.
201 leds[XY(x, y)].nscale8(noise[SMOKENOISE][x][y]);
202
203 }
204 }
205}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define WIDTH
Definition Blur2d.ino:9
#define HEIGHT
Definition Blur2d.ino:10
#define SMOKENOISE
Definition Fire2023.ino:79
uint8_t noise[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:86
#define CentreX
Definition Fire2023.ino:30
#define FLAMEHEIGHT
Definition Fire2023.ino:42
#define SMOKENOISESCALE
Definition Fire2023.ino:53
uint32_t z[NUM_LAYERS]
Definition Fire2023.ino:82
uint8_t XY(uint8_t x, uint8_t y)
Definition Fire2023.ino:208
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint8_t heat[NUM_LEDS]
Definition Fire2023.ino:89
CRGBPalette32 hotPalette
Definition Fire2023.ino:69
#define SMOKESPEED
Definition Fire2023.ino:51
uint32_t scale_y[NUM_LAYERS]
Definition Fire2023.ino:84
#define FIRENOISE
Definition Fire2023.ino:78
#define FIRENOISESCALE
Definition Fire2023.ino:43
#define SMOKENOISE_DIMMER
Definition Fire2023.ino:52
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
#define FIRESPEED
Definition Fire2023.ino:41
#define CentreY
Definition Fire2023.ino:31
uint32_t scale_x[NUM_LAYERS]
Definition Fire2023.ino:83
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:466
@ LINEARBLEND
Linear interpolation between palette entries, with wrap-around from end to the beginning again.
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
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:34

References CentreX, CentreY, ColorFromPalette(), FIRENOISE, FIRENOISESCALE, FIRESPEED, FLAMEHEIGHT, heat, HEIGHT, hotPalette, inoise16(), leds, LINEARBLEND, noise, scale8(), 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: