< GMU:Actors, Traces, Collectives | SS17(Redirected from GMU:Actors, Traces, Collectives/Balls)
Ball[] ballArray = new Ball[50];
void setup() {
size(600, 600);
for (int i =0;i<50;i++){
ballArray[i] = new Ball(random(6),random(6));
}
}
void draw() {
background(255);
for (int i =0;i<50;i++){
ballArray[i].update();
ballArray[i].display(color(200,0,150),color(100,0,150));
}
}
class Ball {
PVector position;
PVector velocity;
Ball(float vx, float vy) {
position = new PVector(100, 100);
velocity = new PVector(vx, vy);
}
void update() {
// Add the current speed to the position.
position.add(velocity);
if ((position.x > width) || (position.x < 0)) {
velocity.x = velocity.x * -1;
}
if ((position.y > height) || (position.y < 0)) {
velocity.y = velocity.y * -1;
}
}
void display(color a, color b){
stroke(a);
fill(b);
ellipse(position.x, position.y, 16, 16);
}
}