Comp 170 Lab 1 - Picture - Jan 25

Goals

1. The book's picture project is here. Download this zip file, save it somewhere persistent, open it, and run the project within BlueJ.

Make some modest changes to the picture. Change the position of at least one component, and the color of another, and add at least one additional component (for example, in class following Lab 0 last week I added a second sun).

2. Edit the source code to create an entirely different picture. Try to eliminate the house entirely, perhaps replacing it with a landscape (trees can be rectangles topped with circles or triangles), or a vehicle, or a face.

3. Add a moveHorizontal(int distance) method to the Picture class, and make it work. You won't need the setBlackandWhite() or setColor methods; you can take over one of those. The way to move the entire picture left is simply to move each component left.

4. Add a Blue Meteor, or something else that moves or otherwise uses a loop to repeat itself. Here are the steps:

(a). Create the outline for a new method:

    public void meteor() {
    }

(b). Create the moving object (it doesn't have to be a circle) inside the method above:

    Circle m = new Circle();

(c). Set its initial size and position and color. Here's one sample change, plus the line needed to make the shape visible:

    m.changeSize(20);
    m.makeVisible();

(d). Now keep redrawing it in a loop. Shown here is a while loop; the for loop is another option. Each time "through" the loop the variable i is incremented; we stop when i reaches 30. Each time we move, we move right by 6 pixels and down by 3; the net effect is an animated slide from upper-left to lower-right.

    int i = 0;
    while(i<30){
        m.moveHorizontal(6);
        m.moveVertical(3);
        i=i+1;
    }
What do you think would happen if you deleted (or, better, commented out) the i=i+1 line?

Suppose you didn't want animation; you just wanted a whole row of circles or triangles? What would you have to do differently?

Show your project to either me or Debjit. Be sure we make a note of it!