CS 140 - Lab 5, Thursday Sep 18

Objectives

  1. Use for-loops to create Java graphics and simple animation.

The Lab

Create a new Java class named Lab5 and save it on your P: drive in a file named Lab5.java. Add a main method and make sure it all compiles before we add anything to it.

To see how your lab will finally look run my version by double clicking on My Computer and going to the folder T:/Harcourt/Fall2008/CS140/Lab5 and then double click on the file run.bat.

  1. What does the following for loop do? (Add it to your lab and find out).
         for (int i = 0; i < 10; i++) {
            StdOut.print(i);
         }   
      
  2. What does the following for-loop do? Be able to explain how it works to me or Dan.
         for (int i = 10; i > 0; i--) {
            StdOut.print(i);
         }   
      
  3. Add to your Lab5 the Java to create and show 600 X 600 blank picture.
  4. Use a for-loop to draw 50 concentric circles. Make the biggest circle 500 pixels wide and high. It should look like below.
  5. Modify your for-loop above so it animates drawing the circles by starting with the outermost circle. Draw a new circle every tenth of a second.
  6. Now animate erasing the circles from the inside out. The code is very similar to above but think about using a for-loop that counts down instead. Draw a new circle every tenth of a second.
  7. Now draw circles like we did initially but draw filled circles and animate them starting with the outer circle. Start the outer circle white and make each circle progressively darker. The final result should look like below.

Extra Credit

Have your code from the previous section draw random colored circles and ovals. Your output might look something like the following.

When you finish make sure you have me or Dan check your work.