Skip to content

Instantly share code, notes, and snippets.

@mikezila
Created March 9, 2017 22:33
Show Gist options
  • Save mikezila/bc22f8997c2d2c237e1b50ab77a06a44 to your computer and use it in GitHub Desktop.
Save mikezila/bc22f8997c2d2c237e1b50ab77a06a44 to your computer and use it in GitHub Desktop.
Life in Apple BASIC
100 size = 10
101 gfx = 5
102 gr
103 color = gfx
200 dim board(size, size)
210 dim temp(size, size)
300 gosub 800 : rem random
310 rem main loop
320 gosub 900 : rem render
330 gosub 600 : rem do rules
340 goto 320
600 rem run rules
605 print "simulating..."
610 for y=0 to size : for x=0 to size
615 live = 0
620 if x - 1 >= 0 then : if board(x - 1, y) = 1 then live = live + 1 : rem left
625 if x + 1 <= size then : if board(x + 1, y) = 1 then live = live + 1 : rem right
630 if y - 1 >= 0 then : if board(x, y - 1) = 1 then live = live + 1 : rem top
635 if y + 1 <= size then : if board(x, y + 1) = 1 then live = live + 1 : rem bottom
640 if x - 1 >= 0 and y - 1 >= 0 then : if board(x - 1, y - 1) = 1 then live = live + 1 : rem top left
645 if x + 1 <= size and y - 1 >= 0 then : if board(x + 1, y - 1) = 1 then live = live + 1 : rem top right
650 if x - 1 >= 0 and y + 1 <= size then : if board(x - 1, y + 1) = 1 then live = live + 1 : rem bottom left
655 if x + 1 <= size and y + 1 <= size then : if board(x + 1, y + 1) = 1 then live = live + 1 : rem bottom right
660 if board(x,y) = 1 and live < 2 then temp(x,y) = 0 : goto 690
665 if board(x,y) = 1 and live > 3 then temp(x,y) = 0 : goto 690
670 if board(x,y) = 1 and live = 2 then temp(x,y) = 1 : goto 690
675 if board(x,y) = 1 and live = 3 then temp(x,y) = 1 : goto 690
680 if board(x,y) = 0 and live = 3 then temp(x,y) = 1 : goto 690
685 if board(x,y) = 0 and live >< 3 then temp(x,y) = 0 : goto 690
690 next x : next y
695 print "moving data..."
700 for y=1 to size : for x=1 to size : board(x,y) = temp(x,y) : next x : next y
710 return
800 rem randomize board
810 print "randomizing..."
820 for y=0 to size : for x=0 to size
830 board(x, y) = int(rnd(1)*2)
840 next x : next y
850 return
400 rem glider spawn
405 board(2,1) = 1
410 board(3,2) = 1
415 board(1,3) = 1
420 board(2,3) = 1
425 board(3,3) = 1
430 return
900 rem render screen
910 print "drawing..."
920 for y=0 to size : for x=0 to size
930 color = 1 : if board(x,y) = 1 then color = gfx
940 plot x, y
950 next x : next y
999 return
@mikezila
Copy link
Author

mikezila commented Mar 9, 2017

This is really slow, and does not handle the edges of the board correctly, but it otherwise works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment