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

◆ Fire2023()

void Fire2023 ( uint32_t now)

Definition at line 129 of file Fire2023.ino.

129 {
130 // some changing values
131 // these values are produced by perlin noise to add randomness and smooth transitions
132 uint16_t ctrl1 = inoise16(11 * now, 0, 0);
133 uint16_t ctrl2 = inoise16(13 * now, 100000, 100000);
134 uint16_t ctrl = ((ctrl1 + ctrl2) >> 1);
135
136 // parameters for the fire heat map
137 x[FIRENOISE] = 3 * ctrl * FIRESPEED;
138 y[FIRENOISE] = 20 * now * FIRESPEED;
139 z[FIRENOISE] = 5 * now * FIRESPEED;
142
143 //calculate the perlin noise data for the fire
144 for (uint8_t x_count = 0; x_count < WIDTH; x_count++) {
145 uint32_t xoffset = scale_x[FIRENOISE] * (x_count - CentreX);
146 for (uint8_t y_count = 0; y_count < HEIGHT; y_count++) {
147 uint32_t yoffset = scale_y[FIRENOISE] * (y_count - CentreY);
148 uint16_t data = ((inoise16(x[FIRENOISE] + xoffset, y[FIRENOISE] + yoffset, z[FIRENOISE])) + 1);
149 noise[FIRENOISE][x_count][y_count] = data >> 8;
150 }
151 }
152
153 // parameters for the smoke map
154 x[SMOKENOISE] = 3 * ctrl * SMOKESPEED;
155 y[SMOKENOISE] = 20 * now * SMOKESPEED;
156 z[SMOKENOISE] = 5 * now * SMOKESPEED;
159
160 //calculate the perlin noise data for the smoke
161 for (uint8_t x_count = 0; x_count < WIDTH; x_count++) {
162 uint32_t xoffset = scale_x[SMOKENOISE] * (x_count - CentreX);
163 for (uint8_t y_count = 0; y_count < HEIGHT; y_count++) {
164 uint32_t yoffset = scale_y[SMOKENOISE] * (y_count - CentreY);
165 uint16_t data = ((inoise16(x[SMOKENOISE] + xoffset, y[SMOKENOISE] + yoffset, z[SMOKENOISE])) + 1);
166 noise[SMOKENOISE][x_count][y_count] = data / SMOKENOISE_DIMMER;
167 }
168 }
169
170 //copy everything one line up
171 for (uint8_t y = 0; y < HEIGHT - 1; y++) {
172 for (uint8_t x = 0; x < WIDTH; x++) {
173 heat[XY(x, y)] = heat[XY(x, y + 1)];
174 }
175 }
176
177 // draw lowest line - seed the fire where it is brightest and hottest
178 for (uint8_t x = 0; x < WIDTH; x++) {
180 //if (heat[XY(x, HEIGHT-1)] < 200) heat[XY(x, HEIGHT-1)] = 150;
181 }
182
183 // dim the flames based on FIRENOISE noise.
184 // if the FIRENOISE noise is strong, the led goes out fast
185 // if the FIRENOISE noise is weak, the led stays on stronger.
186 // once the heat is gone, it stays dark.
187 for (uint8_t y = 0; y < HEIGHT - 1; y++) {
188 for (uint8_t x = 0; x < WIDTH; x++) {
189 uint8_t dim = noise[FIRENOISE][x][y];
190 // high value in FLAMEHEIGHT = less dimming = high flames
191 dim = dim / FLAMEHEIGHT;
192 dim = 255 - dim;
193 heat[XY(x, y)] = scale8(heat[XY(x, y)] , dim);
194
195 // map the colors based on heatmap
196 // use the heat map to set the color of the LED from the "hot" palette
197 // whichpalette position brightness blend or not
198 leds[XY(x, y)] = ColorFromPalette(hotPalette, heat[XY(x, y)], heat[XY(x, y)], LINEARBLEND);
199
200 // dim the result based on SMOKENOISE noise
201 // this is not saved in the heat map - the flame may dim away and come back
202 // next iteration.
203 leds[XY(x, y)].nscale8(noise[SMOKENOISE][x][y]);
204
205 }
206 }
207}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
int y
Definition Audio.ino:72
#define WIDTH
Definition Audio.ino:33
int x
Definition Audio.ino:71
#define HEIGHT
Definition Audio.ino:32
#define SMOKENOISE
Definition Fire2023.ino:81
uint8_t noise[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:88
#define CentreX
Definition Fire2023.ino:32
#define FLAMEHEIGHT
Definition Fire2023.ino:44
#define SMOKENOISESCALE
Definition Fire2023.ino:55
uint32_t z[NUM_LAYERS]
Definition Fire2023.ino:84
uint8_t heat[NUM_LEDS]
Definition Fire2023.ino:91
CRGBPalette32 hotPalette
Definition Fire2023.ino:71
#define SMOKESPEED
Definition Fire2023.ino:53
uint32_t scale_y[NUM_LAYERS]
Definition Fire2023.ino:86
#define FIRENOISE
Definition Fire2023.ino:80
#define FIRENOISESCALE
Definition Fire2023.ino:45
#define SMOKENOISE_DIMMER
Definition Fire2023.ino:54
#define FIRESPEED
Definition Fire2023.ino:43
#define CentreY
Definition Fire2023.ino:33
uint32_t scale_x[NUM_LAYERS]
Definition Fire2023.ino:85
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
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:40
uint16_t XY(uint8_t x, uint8_t y)
Definition blur.cpp:21
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t 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: