xxxxxxxxxx
//28.4
Spot[] spots;
float r = random(2);
void setup() {
size(500, 300);
int numSpots = 100;
int dia = height/numSpots;
spots = new Spot[numSpots];
for (int i =0; i < spots.length; i++) {
float x = dia/2 + i*dia;
float rate = random(0.4, 0.8);
spots[i] = new Spot(x, r, dia, rate*r);
}
noStroke();
}
void draw() {
fill(0,4);
rect(0, 0, width, height);
//
fill(0,10);
ellipse(0,250,600,400);
fill(0,8);
ellipse(250,0,600,400);
for (int i=0; i < spots.length; i++) {
spots[i].move();
spots[i].display();
}
}
class Spot {
float x, y;
float diameter;
float speed;
int direction = 1;
Spot(float xpos, float ypos, float dia, float sp) {
x = xpos;
y = ypos;
diameter = dia;
speed = sp;
}
void move() {
x += (speed * direction);
y += ((speed * 8) * direction);
if ((x> (width - diameter/2)) || (x < diameter/2) || (y > (height-diameter/2) || (y< diameter/2))) {
direction *= -1;
}
}
void change(){
if ((y > (height - (height/2))) || (y < height/2)){
}
}
void display() {
fill(244*r, 215*r, 0*r);
ellipse(x*r, y, diameter*r, diameter*r);
}
}