Skip to content

Instantly share code, notes, and snippets.

@Fortyseven
Last active January 4, 2019 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fortyseven/a2aede69c7ce4cf720202c21dbd37b76 to your computer and use it in GitHub Desktop.
Save Fortyseven/a2aede69c7ce4cf720202c21dbd37b76 to your computer and use it in GitHub Desktop.
local color_table = {0, 2, 8,9, 10, 7}
local buffer = {}
local rand_table = {}
local flame_toggle = true
--------------------------------
function _init()
-- poke(0x5F2C, 7) -- magic
poke(0x5F2C, 3) -- set 64x64 video mode
-- precaclulate some random numbers
for i = 0,256 do
rand_table[i] = flr(rnd(1.5))
end
cls()
-- setup our work buffer; blank it out (color 6 = black)
for y = 0, 63 do
buffer[y] = {}
for x = 0, 63 do
buffer[y][x] = color_table[6]
end
end
-- populate "seed" row
for x = 0, 63 do
buffer[63][x] = 6
end
end
local c = 0
--------------------------------
function _update()
for x = 0, 63 do
for y = 1, 63 do
buffer[y-1][x-rand_table[c]] = (buffer[y][x] - flr(rnd(1.25)))
c += 1
if (c > 256) c = 0 -- faster than modulo
end
end
-- allow player to toggle whether the flame is lit
if (btnp(5)) then
if (flame_toggle) then
flame_toggle = false
for x = 0, 63 do
buffer[63][x] = 6
end
else
flame_toggle = true
for x = 0, 63 do
buffer[63][x] = 0
end
end
end
end
--------------------------------
function _draw()
for y = 0, 63 do
for x = 0, 63 do
pset(x,y,color_table[(buffer[y][x]) ])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment