Advertisement
Guest User

langton's trans ant

a guest
Apr 22nd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. int dirx = 0;
  2. int diry = 1;
  3. int x = 0;
  4. int y = 0;
  5. int omx = 0;
  6. int omy = 0;
  7. color[] tra = { color(91, 207, 250), color(245, 171, 185), color(255, 255, 255)};
  8. void setup()
  9. {
  10. size(displayWidth,displayHeight);
  11. x = round(random(round(width/5)) * 5);
  12. y = round(random(round(height/5)) * 5);
  13. frameRate(5000);
  14. background(0);
  15. noStroke();
  16. }
  17.  
  18. void draw()
  19. {
  20. if(mouseX != 0 && mouseX < 100 && mouseY < 100 && mouseX != omx)
  21. {
  22. background (0);
  23. x = round(random(round(width/5)) * 5);
  24. y = round(random(round(height/5)) * 5);
  25. randDir();
  26. omx = mouseX;
  27. }
  28. color col = get(x,y);
  29. if(col == tra[2])
  30. {
  31. changeDir(1);
  32. fill(tra[0]);
  33. }
  34. else if(col == tra[0])
  35. {
  36. changeDir(1);
  37. fill(tra[1]);
  38. }
  39. else if(col == tra[1])
  40. {
  41. changeDir(-1);
  42. fill(tra[2]);
  43. }
  44. else
  45. {
  46. changeDir(-1);
  47. fill(tra[0]);
  48. }
  49. rect(x,y,10,10);
  50. x += dirx * 10;
  51. y += diry * 10;
  52. }
  53.  
  54. void changeDir(int h)
  55. {
  56. if(dirx == 1){dirx = 0; diry = h; return;}
  57. if(dirx == -1){dirx = 0; diry = -h; return;}
  58. if(diry == 1){diry = 0; dirx = -h; return;}
  59. if(diry == -1){diry = 0; dirx = h; return;}
  60. }
  61.  
  62. void randDir()
  63. {
  64. dirx = 0;
  65. diry = 0;
  66. boolean r1 = random(1) > .5;
  67. boolean r2 = random(1) > .5;
  68. if(r1)
  69. {
  70. if(r2)
  71. {
  72. diry = 1;
  73. }
  74. else
  75. {
  76. diry = -1;
  77. }
  78. }
  79. else
  80. {
  81. if(r2)
  82. {
  83. dirx = 1;
  84. }
  85. else
  86. {
  87. dirx = -1;
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement