Advertisement
Audiation

Logan's Cellular Automaton

Jul 30th, 2013
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. grid = 10
  2. values = 3    '2 - 10.
  3. RETINA off
  4.  
  5. ' The "ant" moves up-down, left-right.
  6. ' If any of a cell's adjacent neighbors are the same value as that cell, both cells are randomized with another value.
  7.  
  8. BCOLOR 75,75,75
  9. grid=grid+2
  10. IF values<2 THEN
  11.     values=2
  12. ENDIF
  13. IF values>10 THEN
  14.     values=10
  15. ENDIF
  16. IF grid<3 THEN
  17.     grid=3
  18. ENDIF
  19. DIM gr(grid,grid),r(10),g(10),b(10)
  20. SLEEP 0.01 'Let the CPU catch up.
  21. r(1)=255
  22. g(1)=0
  23. b(1)=0
  24. r(2)=0
  25. g(2)=255
  26. b(2)=0
  27. r(3)=0
  28. g(3)=0
  29. b(3)=255
  30. r(4)=0
  31. g(4)=255
  32. b(4)=255
  33. r(5)=255
  34. g(5)=0
  35. b(5)=255
  36. r(6)=255
  37. g(6)=255
  38. b(6)=0
  39. r(7)=125
  40. g(7)=125
  41. b(7)=125
  42. r(8)=150
  43. g(8)=0
  44. b(8)=255
  45. r(9)=255
  46. g(9)=150
  47. b(9)=0
  48. r(10)=255
  49. g(10)=255
  50. b(10)=255
  51. SLEEP 0.01
  52. TEXTFONT "Arial Rounded","Bold",10
  53. FOR i=2 TO grid-1
  54.     FOR j=2 TO grid-1
  55.         gr(i,j)=INT(1+(RND*values))
  56.         COLOR r(gr(i,j)),g(gr(i,j)),b(gr(i,j))
  57.         RECT (i*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid),i*(ScreenWidth/grid),j*(ScreenHeight/grid)
  58.         COLOR 0,0,0
  59.         DRAWTEXT STR$(gr(i,j)),(i*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid)
  60.     NEXT
  61. NEXT
  62. loopA:
  63. BEGINDRAW
  64. SLEEP 0.001
  65. a=0
  66. FOR i=2 TO grid-1
  67.     FOR j=2 TO grid-1
  68.         '  BEGINDRAW
  69.         IF gr(i+1,j)=gr(i,j) THEN
  70.             a=a+1
  71.             gr(i,j)=INT(1+(RND*values))
  72.             gr(i+1,j)=INT(1+(RND*values))
  73.             COLOR r(gr(i+1,j)),g(gr(i+1,j)),b(gr(i+1,j))
  74.             RECT ((i+1)*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid),(i+1)*(ScreenWidth/grid),j*(ScreenHeight/grid)
  75.             COLOR 0,0,0
  76.             DRAWTEXT STR$(gr(i+1,j)),((i+1)*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid)
  77.         ENDIF
  78.         IF gr(i,j-1)=gr(i,j) THEN
  79.             a=a+1
  80.             gr(i,j)=INT(1+(RND*values))
  81.             gr(i,j-1)=INT(1+(RND*values))
  82.             COLOR r(gr(i,j-1)),g(gr(i,j-1)),b(gr(i,j-1))
  83.             RECT (i*(ScreenWidth/grid))-(ScreenWidth/grid),((j-1)*(ScreenHeight/grid))-(ScreenHeight/grid),i*(ScreenWidth/grid),(j-1)*(ScreenHeight/grid)
  84.             COLOR 0,0,0
  85.             DRAWTEXT STR$(gr(i,j-1)),(i*(ScreenWidth/grid))-(ScreenWidth/grid),((j-1)*(ScreenHeight/grid))-(ScreenHeight/grid)
  86.         ENDIF
  87.         IF gr(i,j+1)=gr(i,j) THEN
  88.             a=a+1
  89.             gr(i,j)=INT(1+(RND*values))
  90.             gr(i,j+1)=INT(1+(RND*values))
  91.             COLOR r(gr(i,j+1)),g(gr(i,j+1)),b(gr(i,j+1))
  92.             RECT (i*(ScreenWidth/grid))-(ScreenWidth/grid),((j+1)*(ScreenHeight/grid))-(ScreenHeight/grid),i*(ScreenWidth/grid),(j+1)*(ScreenHeight/grid)
  93.             COLOR 0,0,0
  94.             DRAWTEXT STR$(gr(i,j+1)),(i*(ScreenWidth/grid))-(ScreenWidth/grid),((j+1)*(ScreenHeight/grid))-(ScreenHeight/grid)
  95.         ENDIF
  96.         IF gr(i-1,j)=gr(i,j) THEN
  97.             a=a+1
  98.             gr(i,j)=INT(1+(RND*values))
  99.             gr(i-1,j)=INT(1+(RND*values))
  100.             COLOR r(gr(i-1,j)),g(gr(i-1,j)),b(gr(i-1,j))
  101.             RECT ((i-1)*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid),(i-1)*(ScreenWidth/grid),j*(ScreenHeight/grid)
  102.             COLOR 0,0,0
  103.             DRAWTEXT STR$(gr(i-1,j)),((i-1)*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid)
  104.         ENDIF
  105.         COLOR r(gr(i,j)),g(gr(i,j)),b(gr(i,j))
  106.         RECT (i*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid),i*(ScreenWidth/grid),j*(ScreenHeight/grid)
  107.         COLOR 0,0,0
  108.         DRAWTEXT STR$(gr(i,j)),(i*(ScreenWidth/grid))-(ScreenWidth/grid),(j*(ScreenHeight/grid))-(ScreenHeight/grid)
  109.         '  ENDDRAW
  110.     NEXT
  111. NEXT
  112. SLEEP 0.001
  113. ENDDRAW
  114. IF a<>0 THEN
  115.     GOTO loopA
  116. ENDIF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement