## Friday, December 3, 2010

### Forest fire

fastgraphics
graphsize 600,600
font "Arial", 20,100
dim cell(101,101)
cell[50,50]=2
burned = 1
Rem probabilitity to catch fire
p=.3
for turn = 1 to 1000
For x = 2 to 99
For y = 2 to 99
if cell[x-1,y]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x,y-1]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x,y+1]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x+1,y]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x-1,y-1]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x-1,y+1]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x+1,y-1]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x+1,y+1]=2 and cell[x,y]=0 and rand < p then cell[x,y]=3
if cell[x,y]=3 then burned = burned + 1
next y
next x
For x = 2 to 99
For y = 2 to 99
if cell[x,y]=0 then color green
if cell[x,y]=1 then color darkorange
if cell[x,y]=2 then color red
if cell[x,y]=3 then color yellow
if cell[x,y]>1 then cell[x,y]=cell[x,y]-1
rect 6*x,6*y,6,6
next y
next x
color blue
Text 10,10,"Cicle="+turn+" % burned trees=" +(burned/100)
refresh
next turn