More fun with arrays, on Roland Garros clay fields.

// The Roland Garros palette color[] rolandgarros = {#C64F1C, #D9947F, #065440, #668A7E, #FFDA0A, #FFFFFF}; color[] palette; Spot[] spots; // Declare array void setup() { size(600 , 400); palette = rolandgarros; int numSpots = 50; // Number of objects int dia = (width-20)/numSpots; // Calculate diameter spots = new Spot[numSpots]; // Create array for (int i = 0; i < spots.length; i++) { float x = 20+dia/2 + i*(dia); float rate = random(1.0, 3.0); // Create each object spots[i] = new Spot(x,30, dia, rate); } noStroke(); } void draw() { // the orange ground background, with increasing alpha fill(palette[0], 12); rect(10, 10, width-20, height-20); // the white line fill(palette[5], 100); rect(10,10+(height-10)/2, width-20, 10); // the green borders fill(palette[2]); rect(0,0,width, 10); rect(0,height-10,width, 10); rect(0,0,10, height); rect(width-10,0,10, height); //the bouncing balls fill(palette[4]); for (int i=0; i < spots.length; i++) { spots[i].move(); // Move each object spots[i].display(); // Display each object } } class Spot { float x, y; float diameter; float speed; int direction = 1; // Direction of motion (1 is down, -1 is up) // Constructor Spot(float xpos, float ypos, float dia, float sp) { x = xpos; y = ypos; diameter = dia; speed = sp; } void move() { y += (speed * direction); if ((y > (height-10 - diameter/2)) || (y < 10+diameter/2)) { direction *= -1; } } void display() { ellipse(x, y, diameter-1, diameter-1); } }