Skip to content

Instantly share code, notes, and snippets.

@fabienbk
Created April 1, 2019 22:26
Show Gist options
  • Save fabienbk/3a0daae4ee9f9b876336906cdf1b26f4 to your computer and use it in GitHub Desktop.
Save fabienbk/3a0daae4ee9f9b876336906cdf1b26f4 to your computer and use it in GitHub Desktop.
Doom Fire in Excel
Public Const Width = 78
Public Const Height = 26
Public Colors(36)
Sub spread_fire(x, y)
rand = Int(3 * Rnd)
randcool = Int(6 * Rnd)
xshift = x - rand + 1
If xshift <= 0 Then xshift = x
If xshift > Width Then xshift = x
newValue = Cells(y + 1, xshift).Value - (randcool)
If newValue < 0 Then newValue = 0
Cells(y, x).Value = newValue
Cells(y, x).Interior.Color = Colors(newValue)
End Sub
Sub do_fire()
For y = 1 To Height - 1
For x = 1 To Width
Call spread_fire(x, y)
Next x
Next y
End Sub
Sub read_colors()
For x = 1 To 35
Colors(x - 1) = Cells(28, x).DisplayFormat.Interior.Color
Next x
Colors(35) = RGB(255, 255, 255)
End Sub
Sub init_fire()
For y = 1 To Height - 1
For x = 1 To Width
Cells(y, x).Interior.Color = RGB(0, 0, 0)
Cells(y, x).Value = 0
Next x
Next y
For x = 1 To Width
Cells(26, x).Interior.Color = RGB(255, 255, 255)
Cells(26, x).Value = 35
Next x
End Sub
Sub end_fire()
For x = 1 To Width
Cells(26, x).Interior.Color = RGB(0, 0, 0)
Cells(26, x).Value = 0
Next x
End Sub
Sub doom_fire()
Randomize
Call read_colors
Call init_fire
For x = 1 To 100
Call do_fire
Next x
Call end_fire
For x = 1 To 100
Call do_fire
Next x
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment