CS 117 Animation Lab
Today you are going to experiment with primitive Java animation.
Begin by saving, compiling and running the code in
Disk.java and DiskMain.java.
together with a new "double-buffered" version of the Canvas class: DBCanvas.java.
The DBCanvas class changes the way you draw into a canvas slightly in that objects like
rectangles, ovals, etc. are all drawn before the method showBuffer() is called. This allows
for smooth movement.
Follow the moving disk and follow the code to see if you understand what is happening.
Once you do, modify the code in several different ways:
- Make the disk move up and down, instead of side to side.
- Note that the disk goes slightly too far to the right to appear
as if it is bouncing off the wall. Fix this problem and the analogous up/down
problem. Change the size of the disk, by passing a size parameter in the
disk constructor. Make sure your bounce fix works for different size disks.
- Fool around with the wait method to see what happens to the animation.
- Create an array of disks all with random positions, colors, size, and directions
(left, right, up, and down) and animate them.
- Add a speed variable that allows each disk to move at a different
random speed.