Project 3: Scenes within Scenes
The purpose of this assignment is to incorporate loops and conditionals into your code as well as provide more practice in encapsulating code and concepts for later re-use and manipulation.
For this lab you will be re-writing a number of functions from your shapes.py file from lab 2. It's probably best to start fresh and copy over only those functions that don't have to change. The goto function is an example of a function you can copy and paste into the new file.
Create a new file called things.py. Copy over the goto and block
functions from your shapes.py file. Add a parameter called
fill to the block function.
First, re-write the block function to take advantage of looping.
Second, edit the block function so that if the fill variable has the value True, then the block should be filled. If the fill variable has the value False, then the block should not be filled. You will need to use an if-statement before and after the drawing commands for your block.
Don't forget to appropriately comment your functions.
- For at least 2 more of your basic shape functions, copy them to your things.py file, edit them to use loops wherever it makes sense and give them a fill parameter that controls whether the shape is filled or not.
For at least 2 of your more complex shapes, copy them to your
things.py file, rewrite them using the new functions with the fill
parameter and take advantage of looping wherever possible. If you
wish, use conditional statements to enable variations on the complex
shapes. For example, you can make any function call dependent upon a
random number using the following type of test. In the example below,
the block will be drawn 70% of the time.
if random.random() < 0.7: block( x, y, w, h, True )
Pick one of your scenes from lab 2 (or create a new outdoor scene, if
you wish). Copy it to your things.py file and re-write it so the
entire scene is parameterized by an x, y location and a scale
parameter. In other words, you should be able to have your scene draw
anywhere on the screen at any size.
Create a task1.py file that imports things.py and uses the scene function to draw several versions of the scene. Use a command line parameter to control some aspect of the program, such as the number of scenes drawn. The first required picture is an image with three differently sized versions of your outdoor scene.
- Create a task2.py file that creates a simple indoor scene. As part of the indoor scene, make your outdoor scene appear as a window or painting within the indoor scene. Keep the indoor scene inside a function, and use a command line parameter to control some aspect of the image. This image is the second required picture.
- Get both of your outdoor scenes from last week (or new ones you created this week) into the indoor scene as paintings or windows.
- Make use of the range function in creative ways, using 2 or 3 arguments.
- Demonstrate several levels of encapsulation (scenes within scenes within scenes).
- Make complex scenes without using complex code.
- Have the command line arguments control a number of different aspects of the scene.
Make a new wiki page for your assignment. Put the label cs151S10proj3 on the page. Each of you needs to make your own writeup.
In addition to making the wiki page writeup, put the python files you wrote on the Academics server in your handin directory.
In general, your writeup should follow the outline below.
- A brief summary of the task, in your own words. This should be no more than a few sentences. Give the reader context and identify the key purpose of the assignment.
- A description of your solution to the tasks, including any images you created. This should be a description of the form and functionality of your final code. You may want to incorporate code snippets in your description to point out relevant features. Note any unique computational solutions you developed.
- A description of any extensions you undertook, including images demonstrating those extensions. If you added any modules, functions, or other design components, note their structure and the algorithms you used.
- A brief description (1-3 sentences) of what you learned.
- Don't forget to label your writeup so that it appears in the listing on the main wiki page for the course. For this lab, use cs151S10proj3