66 lines
2.2 KiB
Plaintext
66 lines
2.2 KiB
Plaintext
Sub Run()
|
|
//Handy named constants
|
|
Const empty = 0
|
|
Const tree = 1
|
|
Const fire = 2
|
|
Const ablaze = &cFF0000 //Using the &c numeric operator to indicate a color in hex
|
|
Const alive = &c00FF00
|
|
Const dead = &c804040
|
|
|
|
//Our forest
|
|
Dim worldPic As New Picture(480, 480, 32)
|
|
Dim newWorld(120, 120) As Integer
|
|
Dim oldWorld(120, 120) As Integer
|
|
|
|
//Initialize forest
|
|
Dim rand As New Random
|
|
For x as Integer = 0 to 119
|
|
For y as Integer = 0 to 119
|
|
if rand.InRange(0, 2) = 0 Or x = 119 or y = 119 or x = 0 or y = 0 Then
|
|
newWorld(x, y) = empty
|
|
worldPic.Graphics.ForeColor = dead
|
|
worldPic.Graphics.FillRect(x*4, y*4, 4, 4)
|
|
Else
|
|
newWorld(x, y) = tree
|
|
worldPic.Graphics.ForeColor = alive
|
|
worldPic.Graphics.FillRect(x*4, y*4, 4, 4)
|
|
end if
|
|
Next
|
|
Next
|
|
oldWorld = newWorld
|
|
|
|
//Burn, baby burn!
|
|
While Window1.stop = False
|
|
For x as Integer = 0 To 119
|
|
For y As Integer = 0 to 119
|
|
Dim willBurn As Integer = rand.InRange(0, Window1.burnProb.Value)
|
|
Dim willGrow As Integer = rand.InRange(0, Window1.growProb.Value)
|
|
if x = 119 or y = 119 or x = 0 or y = 0 Then
|
|
Continue
|
|
end if
|
|
Select Case oldWorld(x, y)
|
|
Case empty
|
|
If willGrow = (Window1.growProb.Value) Then
|
|
newWorld(x, y) = tree
|
|
worldPic.Graphics.ForeColor = alive
|
|
worldPic.Graphics.FillRect(x*4, y*4, 4, 4)
|
|
end if
|
|
Case tree
|
|
if oldWorld(x - 1, y) = fire Or oldWorld(x, y - 1) = fire Or oldWorld(x + 1, y) = fire Or oldWorld(x, y + 1) = fire Or oldWorld(x + 1, y + 1) = fire Or oldWorld(x - 1, y - 1) = fire Or oldWorld(x - 1, y + 1) = fire Or oldWorld(x + 1, y - 1) = fire Or willBurn = (Window1.burnProb.Value) Then
|
|
newWorld(x, y) = fire
|
|
worldPic.Graphics.ForeColor = ablaze
|
|
worldPic.Graphics.FillRect(x*4, y*4, 4, 4)
|
|
end if
|
|
Case fire
|
|
newWorld(x, y) = empty
|
|
worldPic.Graphics.ForeColor = dead
|
|
worldPic.Graphics.FillRect(x*4, y*4, 4, 4)
|
|
End Select
|
|
Next
|
|
Next
|
|
Window1.Canvas1.Graphics.DrawPicture(worldPic, 0, 0)
|
|
oldWorld = newWorld
|
|
me.Sleep(Window1.speed.Value)
|
|
Wend
|
|
End Sub
|