p_fire = 0.00002
p_tree = 0.002
# 
len f[] 102 * 102
len p[] len f[]
background 100
clear
for r = 0 to 99
   for c = 0 to 99
      i = r * 102 + c + 104
      if randomf < 0.5
         f[i] = 1
      .
   .
.
timer 0
# 
subr show
   for r = 0 to 99
      for c = 0 to 99
         i = r * 102 + c + 104
         h = f[i]
         if h <> p[i]
            move c + 0.5 r + 0.5
            if h = 0
               color 100
               circle 0.6
            elif h = 1
               color 151
               circle 0.5
            else
               color 9 * 100 + (18 - 2 * h) * 10
               circle 0.5
            .
         .
      .
   .
.
subr update
   swap f[] p[]
   for r = 0 to 99
      for c = 0 to 99
         i = r * 102 + c + 104
         if p[i] = 0
            f[i] = 0
            if randomf < p_tree
               f[i] = 1
            .
         elif p[i] = 1
            f[i] = 1
            s = p[i - 103] + p[i - 102] + p[i - 101]
            s += p[i - 1] + p[i + 1]
            s += p[i + 101] + p[i + 102] + p[i + 103]
            if s >= 9 or randomf < p_fire
               f[i] = 9
            .
         elif p[i] = 4
            f[i] = 0
         else
            f[i] = p[i] - 1
         .
      .
   .
.
on timer
   show
   update
   timer 0.2
.
