Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Created April 13, 2019 10:33
Show Gist options
  • Save CapsAdmin/9ce6a30e1d78922b642107363329f4ef to your computer and use it in GitHub Desktop.
Save CapsAdmin/9ce6a30e1d78922b642107363329f4ef to your computer and use it in GitHub Desktop.
gmod lua
local fireBlocks = {}
local tilesize = 8
local numberWidthBlocks = math.floor(ScrW() / tilesize)
local numberHeightBlocks = 48 -- means all the 36 colors with a little more space to remaining flames
local offsetY = ScrH() - (numberHeightBlocks * tilesize)
local colorLookup = {
Color(7,7,7),
Color(31,7,7),
Color(47,15,7),
Color(71,15,7),
Color(87,23,7),
Color(103,31,7),
Color(119,31,7),
Color(143,39,7),
Color(159,47,7),
Color(175,63,7),
Color(191,71,7),
Color(199,71,7),
Color(223,79,7),
Color(223,87,7),
Color(223,87,7),
Color(215,95,7),
Color(215,95,7),
Color(215,103,15),
Color(207,111,15),
Color(207,119,15),
Color(207,127,15),
Color(207,135,23),
Color(199,135,23),
Color(199,143,23),
Color(199,151,31),
Color(191,159,31),
Color(191,159,31),
Color(191,167,39),
Color(191,167,39),
Color(191,175,47),
Color(183,175,47),
Color(183,183,47),
Color(183,183,55),
Color(207,207,111),
Color(223,223,159),
Color(239,239,199),
Color(255,255,25),
}
for i,v in ipairs(colorLookup) do
v.a = (i/#colorLookup) * 255
end
for line = 1,numberHeightBlocks do
table.insert(fireBlocks, {})
local yValue = (line - 1) * tilesize + offsetY
for col = 1,numberWidthBlocks do
if line < numberHeightBlocks - 1 then
table.insert(fireBlocks[line], {x = (col-1) * tilesize, y = yValue, color = 1})
else
table.insert(fireBlocks[line], {x = (col-1) * tilesize, y = yValue, color = 36})
end
end
end
local function draw()
for line, cols in ipairs(fireBlocks) do
for _, block in ipairs(cols) do
surface.SetDrawColor(colorLookup[block.color])
surface.DrawRect(block.x, block.y, tilesize, tilesize)
end
end
end
local nextUpdate = 0
local function update()
if nextUpdate > RealTime() then
return
end
nextUpdate = RealTime() + 1/16
for line = 1,numberHeightBlocks - 1 do
for col = 2,numberWidthBlocks - 1 do
local windDirection = math.random()
local decay = math.floor(math.random() * 3)
local collumn_To_Apply = col
if windDirection < 0.2 then
collumn_To_Apply = (col - 1)
elseif windDirection > 0.8 then
collumn_To_Apply = (col + 1)
end
if fireBlocks[line+1][col].color - decay > 1 then
fireBlocks[line][collumn_To_Apply].color = fireBlocks[line+1][col].color - decay
else
fireBlocks[line][collumn_To_Apply].color = 1
end
end
end
end
hook.Add("HUDPaint", "doom", draw)
hook.Add("Think", "doom", update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment