Automatic Landscape, Redux

This assignment is to be done with your teammate.

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 the landscape that one of you did for the previous 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 graphics.py. Again create a landscape in a 500 x 700 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 center of the sun appears at the left side of the screen at 6 AM (so you see exactly half the sun), and the center of the sun appears at 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 so that you can see 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 Day/Night Builder

How many hours have passed since midnight? 7.5

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 basic arithmetic operators, namely +, -, *, /, and/or %. (Your texbook has other techniques for solving this sort of problem, but even if you have been reading along (and I hope you are!), I don't want you to use them. This problem can be solved purely with arithmetic: using more advanced programming ideas obscures the fact that there is a more straightforward and more efficient approach. Do not use loops or "if" statements.)

If you complete the above successfully (and have good style in your code), you will receive nearly all the points for the assignment. If you get this far, you should feel proud of your achievements! If you want to push yourself harder and go for the last bonus point, you can try to do one or both of the following (that may or may not actually reflect nature):

When finished, submit via Moodle. If you're working with a partner, only one of you needs to submit; but 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.