sysconf topleft
global m[] nc .
background 777
# 
proc show . .
   clear
   scale = 100 / nc
   sz = scale * 0.95
   for i to len m[]
      x = (i - 1) mod nc
      y = (i - 1) div nc
      move x * scale y * scale
      if m[i] = 0
         color 000
      elif m[i] = 1
         color 980
      elif m[i] = 2
         color 338
      else
         color 833
      .
      rect sz sz
   .
.
proc read . .
   s$ = input
   nc = len s$ + 2
   for i to nc
      m[] &= 0
   .
   repeat
      m[] &= 0
      for c$ in strchars s$
         if c$ = "."
            m[] &= 1
         elif c$ = "H"
            m[] &= 2
         elif c$ = "t"
            m[] &= 3
         else
            m[] &= 0
         .
      .
      for i to nc - len s$ - 1
         m[] &= 0
      .
      s$ = input
      until s$ = ""
   .
   for i to nc
      m[] &= 0
   .
.
read
# 
len mn[] len m[]
# 
proc update . .
   for i to len m[]
      if m[i] = 2
         mn[i] = 3
      elif m[i] = 3
         mn[i] = 1
      elif m[i] = 1
         s = 0
         for dx = -1 to 1
            for dy = -1 to 1
               ix = i + dy * nc + dx
               s += if m[ix] = 2
            .
         .
         if s = 2 or s = 1
            mn[i] = 2
         else
            mn[i] = 1
         .
      .
   .
   swap mn[] m[]
.
on timer
   update
   show
   timer 0.5
.
show
timer 0.5
# 
input_data
tH.........
.   .
   ...
.   .
Ht.. ......
