Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. int unit = 40;
  2. int count;
  3. Module[] mods;
  4. int[][] myArrayOfFriends = {
  5. {0, 1, 2, 3},
  6. {3, 2, 1, 0},
  7. {3, 5, 6, 1},
  8. {3, 8, 3, 4} };
  9.  
  10. int[][] myArrayOfPositions = {
  11. {0, 1},
  12. {3, 2},
  13. {3, 5},
  14. {3, 8} };
  15.  
  16.  
  17.  
  18. void setup() {
  19. size(640, 360);
  20. //noStroke();
  21. stroke(255);
  22. int wideCount = width / unit;
  23. int highCount = height / unit;
  24. count = wideCount * highCount;
  25. mods = new Module[count];
  26.  
  27. int index = 0;
  28. for (int y = 0; y < highCount; y++) {
  29. for (int x = 0; x < wideCount; x++) {
  30. mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
  31. }
  32. }
  33.  
  34. //print(mods[0].x);
  35. }
  36.  
  37. void draw() {
  38. background(0);
  39. for (Module mod : mods) {
  40. mod.update();
  41. mod.display();
  42. }
  43. }
  44.  
  45.  
  46. class Module {
  47. int xOffset;
  48. int yOffset;
  49. float x, y;
  50. int unit;
  51. int xDirection = 1;
  52. int yDirection = 1;
  53. float speed;
  54. float myFriendsX, myFriendsY;
  55.  
  56. IntList friends;
  57.  
  58. int friend;
  59.  
  60. // Contructor
  61. Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
  62. xOffset = xOffsetTemp;
  63. yOffset = yOffsetTemp;
  64. x = xTemp;
  65. y = yTemp;
  66. speed = speedTemp;
  67. unit = tempUnit;
  68. //friends = new IntList();
  69. //friends.append(int(random(10)));
  70.  
  71. friend = int(random(40));
  72. }
  73.  
  74. // Custom method for updating the variables
  75. void update() {
  76. x = x + (speed * xDirection);
  77. if (x >= unit || x <= 0) {
  78. xDirection *= -1;
  79. x = x + (1 * xDirection);
  80. y = y + (1 * yDirection);
  81. }
  82. if (y >= unit || y <= 0) {
  83. yDirection *= -1;
  84. y = y + (1 * yDirection);
  85. }
  86. }
  87.  
  88. // Custom method for drawing the object
  89. void display() {
  90. fill(255);
  91. ellipse(xOffset + x, yOffset + y, 6, 6);
  92.  
  93. //print(mods[0].x);
  94.  
  95. //print(mods[0]);
  96. myFriendsX = mods[friend].x + mods[friend].xOffset;
  97. myFriendsY = mods[friend].y + mods[friend].yOffset;
  98.  
  99. line(xOffset + x, yOffset + y, myFriendsX, myFriendsY);
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement