/* ARRAY for MULTIPLE OBJECT MOVEMENT Jeff Thompson April 2011 Not the most effective method (especially when the numbers get larger, but an easier way to move multiple objects) using arrays. */ int howManyBalls = 100; // how many balls to draw int ballSize = 10; // how large are the balls float [] balls = new float[howManyBalls * 4]; // x4 for x,y, xDirection, yDirection void setup() { size(500,500); smooth(); noStroke(); // use a for loop to set all balls to random positions and speeds // +=4 to step ball by ball (each with 4 values) for (int i=0; i= width) { // if at right OR left side balls[i+2] *= -1; // multiply by -1, reversing direction } if (balls[i+1] <=0 || balls[i+1] >= height) { // if at top OR bottom balls[i+3] *= -1; // do the same } ellipse(balls[i], balls[i+1], ballSize,ballSize); } }