// Example of using the Ball class. // We create three ball objects and use their // methods: display(), move(), and collide() // Exercise: // First read an understand the entire program, including // the Ball class. // Then, try the following: // 1. Add another, fourth, Ball to the sketch, say of size 35 // in a color of your chosing. // Use the display(), move() and collide() methods // to check for collisions. Hint: You will have to // collisions for evey pair of Ball objects. // 2. Modify the collide() methods so that when two // balls collide, they swap 10% of their RGB color // values. // Ball b1; Ball b2; Ball b3;
void setup() { size(600, 600);
// Create balls b1 = new Ball(); b2 = new Ball(10, color(45, 50, 250)); b3 = new Ball(50, color(5, 108, 28)); } // setup()
void draw() { background(255);
// draw the balls b1.display(); b2.display(); b3.display(); // Move them b2.move(); b1.move(); b3.move();
// check collisions b1.collide(b2); b1.collide(b3); b2.collide(b3); } // draw()