Advertisement
Audiation

Langton's Ant

Aug 2nd, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GRIDSIZE = 20
  2. SPEED = 0.01 'Lower # = Faster speed.
  3. ''''''''''''''''''''''''''''''''''''''''''''''
  4. BCOLOR 75,75,75
  5. TCOLOR 255,0,0
  6. PRINT "Loading..."
  7. tick=0
  8. size2=GRIDSIZE
  9. size=size2*size2
  10. x=INT((size2+1)/2)
  11. y=INT((size2+1)/2) 'Start in middle
  12. d=2 'Direction. '1:Left,2:Up,3:Right,4:Dwn.
  13. DIM grid(size)
  14. COLOR 255,255,255
  15. FOR i=1 TO size
  16.     grid(i)=0 'Off/White: Background grid.
  17. NEXT
  18. FOR i=1 TO size2
  19.     FOR j=1 TO size2
  20.         RRECT (i*(ScreenWidth/size2))-(ScreenWidth/size2),(j*(ScreenHeight/size2))-(ScreenHeight/size2),i*(ScreenWidth/size2),j*(ScreenHeight/size2),5
  21.     NEXT
  22. NEXT
  23. SLEEP 0.01
  24. CLS tty
  25. WHILE x>0 AND y>0 AND x<size2 AND y<size2
  26.     tick=tick+1
  27.     PRINT tick
  28.     IF grid(x*y)=0 THEN 'If off/White.
  29.         grid(x*y)=1 'Turn on/Black.
  30.         COLOR 0,0,0
  31.         d=d-1 'Turn left
  32.     ELSE
  33.         IF grid(x*y)=1 THEN 'If on/black
  34.             grid(x*y)=0 'Turn off/white
  35.             COLOR 255,255,255
  36.             d=d+1 'Turn right
  37.         ENDIF
  38.     ENDIF
  39.     IF d=0 THEN
  40.         d=4
  41.     ENDIF
  42.     IF d=5 THEN
  43.         d=1
  44.     ENDIF
  45.     IF d=1 THEN
  46.         x=x-1
  47.     ENDIF
  48.     IF d=2 THEN
  49.         y=y-1
  50.     ENDIF
  51.     IF d=3 THEN
  52.         x=x+1
  53.     ENDIF
  54.     IF d=4 THEN
  55.         y=y+1
  56.     ENDIF
  57.     SLEEP speed
  58.     CLS tty
  59.     RRECT (x*(ScreenWidth/size2))-(ScreenWidth/size2),(y*(ScreenHeight/size2))-(ScreenHeight/size2),x*(ScreenWidth/size2),y*(ScreenHeight/size2),5
  60. WEND
  61. PRINT tick
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement