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;
void setup() {
size(600, 400);
palette = rolandgarros;
int numSpots = 50;
int dia = (width-20)/numSpots;
spots = new Spot[numSpots];
for (int i = 0; i < spots.length; i++) {
float x = 20+dia/2 + i*(dia);
float rate = random(1.0, 3.0);
spots[i] = new Spot(x, 30, dia, rate);
}
noStroke();
}
void draw() {
fill(palette[0], 12);
rect(10, 10, width-20, height-20);
fill(palette[5], 100);
rect(10, 10+(height-10)/2, width-20, 10);
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);
fill(palette[4]);
for (int i=0; i < spots.length; i++) {
spots[i].move();
spots[i].display();
}
}
class Spot {
float x, y, diameter, speed;
int direction = 1;
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);
}
}