CS 117 Assignment: Automatically adjustable images 2


In this automatically adjustable image, you will draw a sun or moon in the sky of a landscape. But this time, you'll need to handle the fact that the sun and moon cross the sky every day.

Part 1: Draw a landscape, sun, and moon

If you wish to use your work from the last assignment as a starting point, feel free. Alternatively, you can start over from scratch if you like. Create a directory named landscape2 to store your work, then copy into it the Canvas class that we used in the previous lab. Again create a landscape in a 500 x 500 canvas.

Draw a sun (yellow circle) in the top left corner of the corner, and a crescent moon in the top right corner. Here's how to make a crescent: draw a white circle, then draw another circle that partially overlaps it that is the same color as the background.

Part 2: Make the position of your sun and moon depend on time

The goal of this part of the assignment is to place the sun (or moon) in different places in the sky, depending on time of day. We will keep things simple: assume that the sun appears in full at the left side of the screen at 6 AM, and finally completely vanishes from the right side of the screen at 8 PM. Likewise, the moon crescent completely appears on the left side of the screen at 8 PM, and vanishes from the right side of the screen at 6 AM.

Your program should ask your user how many hours have passed since midnight. The user should then enter an integer indicating how many hours have passed. Thus if the user enters 9, this means that it is 9 AM. If the user enters 23, this means that it is 11 PM. If the user enters 25, this means that it is 1 AM the next day. Your program should then draw the sun or the moon in its correct location. Here is a sample of what the interaction between your program and your user should look like. The user's responses are in red.


Automatic Day/Night Builder

How many hours have passed since midnight? 8

Here is your picture!

You will need to do some arithmetic in a similar fashion to the last assignment to determine precisely where the sun or moon should go. This is all entirely doable using the five arithmetic operators that we looked at in the last lab, namely +, -, *, /, and/or %. (Chapters 5 and 6 in the texbook have other techniques for solving this sort of problem, but even if you have been terribly precocious and are reading ahead or are otherwise aware of such things, you should not use them. I want you to get practice at using these basic ideas.)

When finished, use hsp to submit your landscape2 directory. Indicate in program comments the names of both authors (you and your partner), as well as roughly what fraction of the time each team member spent "driving" at the keyboard. You should be working to give all team members approximately the same amount of time driving.

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


The following optional challenges are only there if you want to try pushing further: they are not required to receive full credit on the assignment.

Challenge 1: adjust the shade of the background color to match the time of day or night.

Challenge 2: adjust the shape of the crescent so that over the course of a 28 day cycle, the moon varies between full moon, crescent moon, and "new" moon (none).