' Life v0.7 - code by Allan Crossman. ' Intolerably slow on anything but a very fast Mac. ' ' It's not quite true life, in that the edge cells are ' always dead (true life I think assumes an infinite grid). ' ' Draw with the mouse, then press G to start the dance. ' Press R to recall the starting pattern. ' Press escape to end. disable done dim birth(8) dim survive(8) clear ' The crucial rules... (can safely be altered) birth(3) = 1 survive(2) = 1 survive(3) = 1 width = 100 ' On a really fast mac you depth = 100 ' can increase these. topleftx = 10 toplefty = 45 bottomrightx = topleftx + width bottomrighty = toplefty + depth dim ocell(width - 1, depth - 1) ' Cells for odd iterations. dim ecell(width - 1, depth - 1) ' Cells for even iterations. dim scell(width - 1, depth - 1) ' Starting cells (for recall). for x = 0 to width - 1 for y = 0 to depth - 1 ecell(x, y) = 0 ocell(x, y) = 0 scell(x, y) = 0 next y next x iteration = 1 resize console topleftx, toplefty, bottomrightx, bottomrighty set console title to "Life" cls forecolor 65535, 65535, 0 drawloop: if button then x = getmousex y = getmousey if (x > 0) and (y > 0) and (x < width - 1) and (y < depth - 1) then ocell(x, y) = 1 scell(x, y) = 1 plot x, y end if end if if inkey$ = "Q" or inkey$ = "q" or inkey$ = chr$(27) then end if inkey$ = "G" or inkey$ = "g" then goto startmain goto drawloop startmain: virtue = init screen(0, 0, width, depth) set screen to virtue main: if inkey$ = "Q" or inkey$ = "q" or inkey$ = chr$(27) then kill screen virtue end end if if inkey$ = "R" or inkey$ = "r" then set screen to console kill screen virtue cls for x = 0 to width - 1 for y = 0 to depth - 1 ecell(x, y) = 0 if scell(x, y) = 1 then ocell(x, y) = 1 plot x, y else ocell(x, y) = 0 end if next y next x iteration = 1 goto drawloop end if cls if iteration mod 2 = 1 then for x = 1 to width - 2 for y = 1 to depth - 2 n = 0 n = n + ocell(x - 1, y) + ocell(x - 1, y + 1) + ocell(x - 1, y - 1) + ocell(x + 1, y) + ocell(x + 1, y + 1) + ocell(x + 1, y - 1) + ocell(x, y - 1) + ocell(x, y + 1) if ocell(x, y) = 1 then if survive(n) = 1 then ecell(x, y) = 1 plot x, y else ecell(x, y) = 0 end if else if birth(n) = 1 then ecell(x, y) = 1 plot x, y else ecell(x, y) = 0 end if end if next y next x else for x = 1 to width - 2 for y = 1 to depth - 2 n = 0 n = n + ecell(x - 1, y) + ecell(x - 1, y + 1) + ecell(x - 1, y - 1) + ecell(x + 1, y) + ecell(x + 1, y + 1) + ecell(x + 1, y - 1) + ecell(x, y - 1) + ecell(x, y + 1) if ecell(x, y) = 1 then if survive(n) = 1 then ocell(x, y) = 1 plot x, y else ocell(x, y) = 0 end if else if birth(n) = 1 then ocell(x, y) = 1 plot x, y else ocell(x, y) = 0 end if end if next y next x end if iteration = iteration + 1 copyrect 0, 0, width, depth, 0, 0, width, depth, 0, virtue, 0 goto main