Program listing DEFINT A-Z 'integers are faster DECLARE SUB Init 'Allows switching on cells DECLARE SUB Go () 'Allows switching on cells DECLARE SUB Edge 'Draws edge cells DIM SHARED L(47, 34), T(47, 34) 'Life/Temp cell arrays DIM SHARED E(17), count 'life/death array & count start: CLEAR 'null all arrays for restarts E(3) = 1: E(11) = 1: E(12) = 1 '3 neighbours give life to 'dead cell, 2 or 3 keep live cell (value=9) alive. 'All other E() stay equal to 0 and kill cell. Init Go GOTO start END SUB Edge FOR r = 1 TO 33 IF L(0, r) = 1 THEN LINE (1, r * 10 + 1)-STEP(10, 7), 1, BF IF L(47, r) = 1 THEN LINE (612, r*10 +1)-STEP(10, 7), 1, BF NEXT FOR c = 0 to 47 IF L(c, 0) = 1 THEN LINE (c * 13 + 1, 1)-STEP(10, 7), 1, BF IF L(c, 34) = 1 THEN LINE (c*13 +1, 341)-STEP(10, 7), 1, BF NEXT PRINT " Esc to quit. Any other key to pause and restart." count = count + 1: PRINT count END SUB SUB Go DO SCREEN 9, , 1, 0: CLS 'display page 0, draw on page 1 Edge 'draw any live edge cells & message FOR r = 1 TO 33: FOR c = 1 TO 46 'edge cells not changed ru = r - 1: rd = r + 1: cl = c - 1: cr = c + 1 'Count "live" cells adjacent. Add 9 if cell itself alive. 's can have any value 0-8 if cell dead, 9-17 if cell alive s = L(cl, rd) + L(cl, r) + L(cl, ru) + L(c, rd) + L(c, ru) s = s + L(cr, rd) + L(cr, r) + L(cr, ru) + 9 * L(c, r) T(c, r) = E(s) 'set life/death of T()using fixed array E() x = c * 13 + 1: y = r * 10 + 1 IF T(c, r) = 1 THEN LINE (x, y)-STEP(10, 7), 1, BF NEXT: NEXT 'routine, m$ = INKEY$: IF m$ > °" to END IF, here if desired SCREEN 9, , 0, 1: CLS 'switch pages & use T() to calc L() Edge FOR r = 1 TO 33: FOR c = 1 TO 46 ru = r - 1: rd = r + 1: cl = c - l: cr = c + 1 s = T(cl, rd) + T(cl, r) + T(cl, ru) + T(c, rd) + T(c, ru) s = s + T(cr, rd) + T(cr, r) + T(cr, ru) + 9 * T(c, r) L (c, r) = E (s) : x = c * 13 + 1: y = r * 10 + 1 IF L(c, r) = 1 THEN LINE (x, y)-STEP(10, 7), 1, BF NEXT: NEXT m$ = INKEY$ IF m$ > "" THEN 'if key SELECT CASE m$ CASE CHR$(27): CLS : EXIT DO 'escape CASE ELSE: DO: LOOP WHILE INKEY$ 'pause for key END SELECT END IF LOOP 'keep going END SUB SUB Init SCREEN 9, , 0, 0'EGA 640 X 350. Use 48 cells across, 35 down LINE (13, 10)-STEP(598, 330), 4, B 'cells outside are stable PRINT "Cursors. Space toggles life. ENTER starts. Esc ends" c = 24: r = 17 'initial column, row D0 'outer loop x = c * 13: y = r * 10 'cells 13 X 10 pix. DO 'flash cell border IF TIMER > RefTime! THEN 'check if .3 sees up RefTime! = TIMER + .3: col = 1 - col 'colour flips 0/1/0 LINE (x, y)-STEP(12, 9), Col, B 'draw border END IF c$ = INKEY$ 'check keystroke LOOP WHILE c$ _ "" LINE (x, y)-STEP(12, 9), 0, B 'check keystroke SELECT CASE c$ 'obey key CASE CHR$(27): END 'Escape CASE CHR$(13): EXIT SUB 'Enter starts `Go' CASE CHR$(32): L(c, r) = 1 - L(c, r) 'Spacebar flips cell LINE (x + 1, y + 1)-STEP(10, 7), L(c 'fill cell T(c, r) = L(c, r) 'edge cells need T() = L() CASE CHR$(0) + CHR$(75): c = (c + 47) MOD 48 'left CASE CHR$(0) + CHR$(77): c = (c + 1) MOD 48 'right CASE CHR$(0) + CHR$(72): r = (r + 34) MOD 35 'up CASE CHR$(0) + CHR$(80): r = (r + 1) MOD 35 'down CASE ELSE 'do nothing END SELECT 'modular arithmetic handles screen edge problem LOOP END SUB