1 rem ***  life  ***
2 rem  a demo for basic64: conway's game of life,
3 rem  seeded with the "acorn" - seven live cells
4 rem  that grow, unguided, for thousands of
5 rem  generations before they settle.
6 rem
7 rem  live cells burn gorse fire-yellow on a
8 rem  birchnight midnight-blue field.
9 rem
10 rem  sc (line 100) is the cell size in pixels:
11 rem  4 for a lively field, 1 for a vast slow one.
12 rem
100 sc = 4
110 gw = gramaxx : gh = gramaxy
120 cols = int(gw / sc) : rows = int(gh / sc)
130 dim a(cols, rows) : dim b(cols, rows)
140 rem  clear the field to birchnight blue
142 cls
145 color 255,255,255,18,18,48
150 for yy = 0 to gh : line (0, yy)-(gw, yy), 18, 18, 48 : next yy
160 rem  seed the acorn at the centre
170 ox = int(cols / 2) - 3 : oy = int(rows / 2) - 1
180 a(ox + 1, oy) = 1
190 a(ox + 3, oy + 1) = 1
200 a(ox, oy + 2) = 1 : a(ox + 1, oy + 2) = 1
210 a(ox + 4, oy + 2) = 1 : a(ox + 5, oy + 2) = 1 : a(ox + 6, oy + 2) = 1
220 rem  draw the seed
230 for j = 1 to rows - 2
240 for i = 1 to cols - 2
250 if a(i, j) = 0 then goto 280
260 bx = i : by = j : pr = 255 : pg = 190 : pb = 30 : gosub 9000
280 next i
290 next j
300 rem  ---  the generations  ---
310 for g = 1 to 32000
315 locate 1,1:print "Generation"g
320 for j = 1 to rows - 2
330 for i = 1 to cols - 2
340 nc = a(i-1,j-1) + a(i,j-1) + a(i+1,j-1) + a(i-1,j) + a(i+1,j) + a(i-1,j+1) + a(i,j+1) + a(i+1,j+1)
350 ns = 0
360 if a(i, j) = 1 and (nc = 2 or nc = 3) then ns = 1
370 if a(i, j) = 0 and nc = 3 then ns = 1
380 b(i, j) = ns
390 if ns = a(i, j) then goto 440
400 bx = i : by = j
410 pr = 18 : pg = 18 : pb = 48
420 if ns = 1 then pr = 255 : pg = 190 : pb = 30
430 gosub 9000
440 next i
450 next j
460 for j = 1 to rows - 2
470 for i = 1 to cols - 2
480 a(i, j) = b(i, j)
490 next i
500 next j
510 next g
520 end
9000 x1 = bx * sc : y1 = by * sc
9010 for yy = y1 to y1 + sc - 1
9020 line (x1, yy)-(x1 + sc - 1, yy), pr, pg, pb
9030 next yy
9040 return
