Announcements
- Accountability Group Assignments
- arrange to meet this week
- Quiz 02 is actually happening this week
- Rest of week:
- finishing objects and memory
- starting object inheritance
Lab 03: Bouncing Disks
Two new features:
- Object instances represented in graphical form
- Animation
Bouncing Disk
A BouncingDisk
stores
- position
- velocity
- radius
- color
Primary instance methods
- draw itself on a
Graphics
object
- update its new state
Animation in Theory
- Sequence of frames displayed in rapid succession
- 24 fps $\implies \sim 42$ ms per frame for movies
- $\sim 60$ fps $\implies \sim 17$ ms per frame modern broadcast
- Each frame differs incrementally from previous
- Gives illusion of motion
Animation in Code
Draw/update loop:
while(true){
world.update(1.0 / (double) FPS);
this.repaint();
try{
Thread.sleep(1000/FPS);
}
catch(InterruptedException e){
System.err.println("Thread interrupted.");
return;
}
}
Animating Motion
A moving object:
- position
- velocity (speed + direction)
- units: pixels / second
- how to update for next frame?
How to Represent Bouncing?
Your Task
- Complete
Pair
class
- reprsents vector $(x, y)$-coordinates
- no explicit instructions
- error messages tell you what is missing
- remark: multiple constructors possible!
- Extensions
- disks accelerate due to gravity?
- disks change color over time?
- disks interact with each other?