Advertisement
Audiation

Langton's Ant: 6 Colors

Aug 2nd, 2013
360
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. ' 0: Off, 1: Turn Left, 2: Turn Right.
  5. ' White and Black should not be off.
  6. ' Colors must be in order. (Red>Green>etc)
  7. ' If a color is off, it returns to white.
  8. WHITE = 1
  9. BLACK = 2
  10. RED = 1
  11. GREEN = 2
  12. BLUE = 1
  13. YELLOW = 2
  14. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  15. ' Version 2: 6 colors, seconds counter, better loading information, and custom pattern settings.
  16.  
  17. BCOLOR 75,75,75
  18. TCOLOR 255,0,255
  19. CLS tty
  20. PRINT "Loading...","• Size:",gridsize,"x",gridsize,"("+STR$(gridsize*gridsize)+" cells)"
  21. PRINT "Setting variables..."
  22. IF white=0 THEN
  23.     white=1+(INT(RND*2))
  24. ENDIF
  25. IF black=0 THEN
  26.     black=1+(INT(RND*2))
  27. ENDIF
  28. tick=0
  29. size2=GRIDSIZE
  30. size=size2*size2
  31. x=INT((size2+1)/2)
  32. y=INT((size2+1)/2) 'Start in middle
  33. d=2 'Direction. '1:Left,2:Up,3:Right,4:Dwn.
  34. DIM grid(size)
  35. COLOR 255,255,255
  36. CLS tty
  37. PRINT "Loading...","• Size:",gridsize,"x",gridsize,"("+STR$(gridsize*gridsize)+" cells)"
  38. PRINT "Generating array..."
  39. FOR i=1 TO size
  40.     grid(i)=0 'Off/White: Background grid.
  41. NEXT
  42. CLS tty
  43. PRINT "Loading...","• Size:",gridsize,"x",gridsize,"("+STR$(gridsize*gridsize)+" cells)"
  44. PRINT "Drawing grid..."
  45. FOR i=1 TO size2
  46.     FOR j=1 TO size2
  47.         RRECT (i*(ScreenWidth/size2))-(ScreenWidth/size2),(j*(ScreenHeight/size2))-(ScreenHeight/size2),i*(ScreenWidth/size2),j*(ScreenHeight/size2),5
  48.     NEXT
  49. NEXT
  50. SLEEP 0.01
  51. CLS tty
  52. t1=TickCount
  53. WHILE x>0 AND y>0 AND x<size2 AND y<size2
  54.     tick=tick+1
  55.     t2=TickCount
  56.     PRINT tick,"•",STR$(INT(t2-t1))
  57.     IF grid(x*y)=0 THEN 'If White.
  58.         grid(x*y)=1 'Turn Black.
  59.         COLOR 0,0,0
  60.         d=d+(-3+(white*2)) 'Turn
  61.     ELSE
  62.         IF grid(x*y)=1 THEN 'If black
  63.             IF red<>0 THEN
  64.                 grid(x*y)=2 'Turn red
  65.                 COLOR 255,0,0
  66.             ELSE
  67.                 grid(x*y)=0 'Turn white
  68.                 COLOR 255,255,255
  69.             ENDIF                
  70.             d=d+(-3+(black*2)) 'Turn
  71.         ELSE
  72.             IF grid(x*y)=2 THEN 'if red
  73.                 IF green<>0 THEN
  74.                     grid(x*y)=3 'Turn green
  75.                     COLOR 0,255,0
  76.                 ELSE
  77.                     grid(x*y)=0 'Turn white
  78.                     COLOR 255,255,255
  79.                 ENDIF
  80.                 d=d+(-3+(red*2)) 'Turn
  81.             ELSE
  82.                 IF grid(x*y)=3 THEN 'if green
  83.                     IF blue<>0 THEN
  84.                         grid(x*y)=4 'Turn blue
  85.                         COLOR 0,0,255
  86.                     ELSE
  87.                         grid(x*y)=0 'Turn white
  88.                         COLOR 255,255,255
  89.                     ENDIF
  90.                     d=d+(-3+(green*2)) 'Turn
  91.                 ELSE
  92.                     IF grid(x*y)=4 THEN 'if blue
  93.                         IF yellow<>0 THEN
  94.                             grid(x*y)=5 'Turn yellow
  95.                             COLOR 255,255,0
  96.                         ELSE
  97.                             grid(x*y)=0 'Turn white
  98.                             COLOR 255,255,255
  99.                         ENDIF
  100.                         d=d+(-3+(blue*2)) 'Turn
  101.                     ELSE
  102.                         IF grid(x*y)=5 THEN 'if yello.
  103.                             grid(x*y)=0 'Turn white
  104.                             COLOR 255,255,255
  105.                             d=d+(-3+(yellow*2))
  106.                         ENDIF
  107.                     ENDIF
  108.                 ENDIF
  109.             ENDIF
  110.         ENDIF
  111.     ENDIF
  112.     RRECT (x*(ScreenWidth/size2))-(ScreenWidth/size2),(y*(ScreenHeight/size2))-(ScreenHeight/size2),x*(ScreenWidth/size2),y*(ScreenHeight/size2),5
  113.     IF d=0 THEN
  114.         d=4
  115.     ENDIF
  116.     IF d=5 THEN
  117.         d=1
  118.     ENDIF
  119.     IF d=1 THEN
  120.         x=x-1
  121.     ENDIF
  122.     IF d=2 THEN
  123.         y=y-1
  124.     ENDIF
  125.     IF d=3 THEN
  126.         x=x+1
  127.     ENDIF
  128.     IF d=4 THEN
  129.         y=y+1
  130.     ENDIF
  131.     SLEEP speed
  132.     CLS tty
  133. WEND
  134. t3=TickCount
  135. PRINT STR$(tick),"ticks."
  136. PRINT STR$(INT(t3-t1)),"seconds."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement