Skip Site NavigationCarleton College: Home
 
 

This assignment is to be done individually without your teammate. You can talk to other people in the class (including your teammate), me (Dave), the prefector, and lab assistants for ideas and to gain assistance. You can help each other debug programs, if you wish. The code that you write should be your own, however, and you shouldn't hand a printout of your program to others. See the course syllabus for more details or just ask me if I can clarify.

Part 0: Overview

Many aspects of backgrounds and landscapes that you see in today's movies are computer enhanced. Perhaps the weather was wrong on the day the film was shot, or maybe the director had a change of mind involving the mood. For this assignment, you will create an image that can be changed and adjusted by the user.

Part 1: Draw a landscape and cloud

Create a directory named landscape1 to store your work, then copy into it the Canvas.java class that we used in the previous lab. Write Java code to make a canvas of size 500 pixels wide and 500 pixels high, then draw a simple landscape. Your landscape doesn't have to be particularly fancy, especially if your artistic skills are as bad as mine. Set the background to blue to represent a sky, then draw a couple of rough hills or buildings using ovals or rectangles.

Draw a small white cloud at the top left corner off your canvas. Your cloud can be as simple as a cloud-sized oval, but feel free to use multiple overlapping ovals or other techniques to make your cloud as attractive as you like.

Part 2: Make the position of your cloud adjustable

The goal of this part of the assignment is to place the cloud in different places in the sky, depending on where the user of your program wants it. Specifically, your program should ask your user for a wind speed (in miles per hour), and the number of hours that have passed since the cloud first appeared in the top left of the window. Your program should then draw the cloud in its correct location. Assume that the image is 20 miles across, and that the wind is blowing directly to the right. Here is a sample of what the interaction between your program and your user should look like. The user's responses are in red so that you can tell what the user has typed. (In reality, though, this should appear in the same color as all the other text in your terminal window).


Automatic Landscape Builder

What is the windspeed in miles per hour? 3.5
How many hours have passed? 2.5

Here is your picture!

You will need to do some arithmetic to determine precisely where the cloud should go:

  • If you divide the number of pixels across by the number of miles across, this will tell you how many pixels are in a mile.
  • If you multiply the wind speed times the number of hours that have passed, this will tell you how many miles the cloud has traveled.
  • If you multiply the number of miles that the cloud has traveled by the number of pixels in a mile, this will tell you the number of pixels in the image that the cloud has traveled.
  • After you have figured out the number of pixels that that the cloud has traveled, you have to round it off to an integer. (A cloud cannot start at half a pixel.) Here is sample code that does rounding:
    double num1 = 3.2;
    int num2 = (int)(Math.round(num1));
    

Finally, here are some things you can do to test your code:

  • If windspeed = 20 and hours = 0.5, the left side of the cloud should appear halfway across the window.
  • If windspeed = 10 and hours = 1, the left side of the cloud should appear halfway across the window.
  • If windpseed = 10 and hours = 1.5, the left side of the cloud should appear 3/4 of the way across the screen.

When finished, use hsp to submit your landscape1 directory.

Good luck, and have fun! Remember that lab assistants are available in the evenings in CMC 306 to help out if you need it, and you can attend prefect sessions as well.

Available from: Monday, April 2 2007, 07:55 AM
Due date: Wednesday, April 4 2007, 11:55 PM