Code:
' comment out to remove flamethrower
#define flamethrower
#define ft_width 9
' comment out to remove sparkle effect
#define sparkles 20
' comment out to fade smoothly
#define randomize_vertical
' simulates flickering from wind
#define randomize_horizontal
' Size of the screen
#define sw 320
#define sh 200
' Space on the right and left between fire and edge of screen
#define margin 40
screenres sw, sh, 8
' Now we set the palette
c = 0
' start with a 16 color light blue (200,200,255) -> white gradient
for x = 0 to 15
y = x * 55 \ 15
palette c, 200+y, 200+y, 255
c += 1
next x
' then an 84 color white to yellow gradient
for x = 0 to 83
palette c, 255, 255, 255 - x * 255 \ 83
c += 1
next x
' 20 color yellow -> dark red (215, 0, 0)
for x = 0 to 15+4
red = 255-(x shl 2)
palette c, red, 255 - x * 255 \ (15+4), 0
c += 1
next x
' 8 color dark red -> smokey gray (108, 108, 108)
for x = 0 to 7
palette c, red - x * (red-108) \ 7, x * 108 \ 7, x * 108 \ 7
c += 1
next x
' 128 color smokey gray -> black
for x = 0 to 127
y = 108 - (x * 108 \ 127)
palette c, y, y, y
c += 1
next x
' clear the screen to black
color , 255
cls
randomize timer
dim as ubyte ptr scrn, p0, p1, p2
n = 1
ftd = 1
do
#ifdef sparkles
' Draw some pixels at random locations
' the intensitiy increases downward (192 at the top, 0 at the bottom)
for c = 1 to sparkles
y = int(rnd * (sh - 1))
pset (int(rnd * (sw-2)) + 1, y), 192 - (y * 192 \ sh)
next c
#endif
screenlock
scrn = screenptr
' Randomize the bottom row of pixels
xs = margin ' Where the fire starts
xe = sw-1-margin ' Where the fire ends
p0 = scrn + sw * (sh - 1) ' pointer to bottom row
for x = xs to xe
p0[x] = (p0[x] * 2 + int(rnd * 210)) \ 3
next x
#ifdef flamethrower
ftx += ftd ' move the flamethrower
' make it bounce
if ftx < 1 or ftx >= sw-ft_width-1 then ftd = -ftd
' draw it
p0[ftx] = 160
for x = ftx+1 to ftx+ft_width-1
p0[x] = 0
next x
p0[x] = 160
#endif
p0 = scrn ' pointer to the top row of pixels
p1 = p0 + sw ' the next row
p2 = p1 + sw ' and the row after that
' Loop over all but the last 2 rows
for y = 0 to sh-3
#ifdef randomize_vertical
n = int(rnd * 3)
#endif
#ifdef randomize_horizontal
d = int(rnd * 3) - 1
#endif
' Loop over all but the first and last column
for x = 1 to sw-2
xd = x + d
if xd < 1 or xd > sw-2 then xd = x
' Take the average of a 3x2 block of pixels at (xd, y)
' giving the top row twice as much weight
c = p1[xd-1] + p1[xd] + p1[xd+1]
c = c+c + p2[xd-1] + p2[xd] + p2[xd+1]
c = c \ 9
' Fade the pixel a little (blue->white->yellow->red->grey->black)
c += n
if c > 255 then c = 255
p0[x] = c
next x
' Advance the pointers to the next row
p0 += sw
p1 += sw
p2 += sw
next y
' Do the second to bottom row
p0 = scrn + (sh-2) * sw ' pointer to row sh-2
p1 = p0 + sw ' pointer to the row below p0 (the last row, sh-1)
for x = 1 to sw-2
' Take the average of a 3x1 block of pixels
c = (p1[x-1] + p1[x] + p1[x+1]) \ 3
' Fade the pixel a little (blue->white->yellow->red->grey->black)
c += 2
if c > 255 then c = 255
p0[x] = c
next x
screenunlock
' Wait 8 milliseconds
sleep 8
' Stop looping if the user has pressed a key
loop until len(inkey$)
end