HW5: Automatic Landscape II

25 points; due Mon 4/14 @ 9am.

Goals

The goal of this assignment is to use math to make a partial simulation of the world.

Setup and Requirements

You may work with a partner of your choice for this assignment. All work is to be done with both teammates working together at the computer. If you find that you absolutely can't schedule time to work together, split up for this assignment and turn in your own work.

If you work alone, put your name in a comment at the top of each file you submit. If you work in a pair, put both names at the top. Only one member of your team should submit your work; don't submit the same work from multiple accounts.

As always, ask lots of questions! Talk with classmates, the prefect, lab assistants, or me, or post on Piazza.

Your Assignment

Overview

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.

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 graphics.py into it. 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.

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:

Your program should ask your user how many hours have passed since midnight. The user should then enter a number indicating how many hours have passed. Thus if the user enters 9, this means that it is 9 AM. If the user enters 22.5, this means that it is 10:30 PM. If the user enters 25, this means that it is 1 AM the next day. You should make no assumptions about the range of values your user might enter; you may assume that they'll enter a number, though.

Here is a sample of what the interaction between your program and your user should look like. The user's responses are in red, with a dotted underline, 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 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.)

A little extra polish

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 point, you can try to do one or both of the following (that may or may not actually reflect nature):

Implementing these features will probably require some functions from the math module. You can access them by putting from math import * at the top of your source code, and you can read about what's available from the online documentation. Parabolas, trigonometry, etc. might help you in building these features. As above, “if”s and loops are not allowed for these features.

Submission and Grading

When you are finished, submit your work through Moodle. You do not need to include graphics.py or any files ending with .pyc. If you have only one file to submit, turn that in; otherwise, create a zip file called hw5.zip and submit that.

Again, only one member of a team needs to submit the work, but make sure that both team members' names are in comments at the top of each source-code file.

Grading