Advertisement
SciQuest_csp

Langton's Ant, Main

Mar 31st, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. black = color(0, 0, 0, 255)
  2. red = color(255, 0, 0, 255)
  3. blue = color(2, 0, 255, 255)
  4. yellow = color(251, 255, 0, 255)
  5. green = color(2, 255, 0, 255)
  6. white = color(255, 255, 255, 255)
  7. purple = color(255, 0, 252, 255)
  8. cyan = color(0,255,255,255)
  9. grey = color(127, 127, 127, 255)
  10. brown = color(111, 87, 31, 255)
  11. octarine = color(71, 31, 106, 255)
  12.  
  13. L = true
  14. R = false
  15.  
  16. function setup()
  17.     parameter("Scale", 1, 15, 1)
  18.     parameter("Speed", 0, 4, 2)
  19.    
  20.     offset = vec2(WIDTH/2, HEIGHT/2)
  21.    
  22.     board = image(WIDTH, HEIGHT, red)
  23.     fred = Ant(vec2(0,1), offset.x, offset.y, {R,L,R,L, R,L, L,R,L,R})
  24.     jeff = Ant(vec2(1,0), 0, 0, {R,L})
  25. colors={black,red,blue,yellow,green,white,purple,cyan,brown,octarine}
  26. end
  27.  
  28. function draw()
  29.     background(40, 40, 50)
  30.     spriteMode(CENTER)
  31.    
  32.     scale(Scale)
  33.     sprite(board, offset.x/Scale, offset.y/Scale)
  34.  
  35.     spd = math.floor(10^Speed)
  36.     for i = 1,spd do
  37.         fred:go(board)
  38.         jeff:go(board)
  39.     end
  40. end
  41.  
  42. function touched(t)
  43.     offset.x = offset.x + t.deltaX
  44.     offset.y = offset.y + t.deltaY
  45.     if t.tapCount == 2 then
  46.         offset.x = WIDTH/2
  47.         offset.y = HEIGHT/2
  48.     end
  49. end
  50.  
  51. function colorEqual(x,y)
  52.     if x.r==y.r and x.g==y.g and x.b==y.b then
  53.         return true
  54.     end
  55.     return false
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement