Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int unit = 40;
- int count;
- Module[] mods;
- int[][] myArrayOfFriends = {
- {0, 1, 2, 3},
- {3, 2, 1, 0},
- {3, 5, 6, 1},
- {3, 8, 3, 4} };
- int[][] myArrayOfPositions = {
- {0, 1},
- {3, 2},
- {3, 5},
- {3, 8} };
- void setup() {
- size(640, 360);
- //noStroke();
- stroke(255);
- int wideCount = width / unit;
- int highCount = height / unit;
- count = wideCount * highCount;
- mods = new Module[count];
- int index = 0;
- for (int y = 0; y < highCount; y++) {
- for (int x = 0; x < wideCount; x++) {
- mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
- }
- }
- //print(mods[0].x);
- }
- void draw() {
- background(0);
- for (Module mod : mods) {
- mod.update();
- mod.display();
- }
- }
- class Module {
- int xOffset;
- int yOffset;
- float x, y;
- int unit;
- int xDirection = 1;
- int yDirection = 1;
- float speed;
- float myFriendsX, myFriendsY;
- IntList friends;
- int friend;
- // Contructor
- Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
- xOffset = xOffsetTemp;
- yOffset = yOffsetTemp;
- x = xTemp;
- y = yTemp;
- speed = speedTemp;
- unit = tempUnit;
- //friends = new IntList();
- //friends.append(int(random(10)));
- friend = int(random(40));
- }
- // Custom method for updating the variables
- void update() {
- x = x + (speed * xDirection);
- if (x >= unit || x <= 0) {
- xDirection *= -1;
- x = x + (1 * xDirection);
- y = y + (1 * yDirection);
- }
- if (y >= unit || y <= 0) {
- yDirection *= -1;
- y = y + (1 * yDirection);
- }
- }
- // Custom method for drawing the object
- void display() {
- fill(255);
- ellipse(xOffset + x, yOffset + y, 6, 6);
- //print(mods[0].x);
- //print(mods[0]);
- myFriendsX = mods[friend].x + mods[friend].xOffset;
- myFriendsY = mods[friend].y + mods[friend].yOffset;
- line(xOffset + x, yOffset + y, myFriendsX, myFriendsY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement