CS 150 - Assignment 2

Due: Wednesday 3/1 at the beginning of class

For this assignment, we will be using the turtle graphics module to draw a picture. For your prelab, you should have designed the drawing and figured out the rough placement of the different components. See the prelab for the details of what should be included in your drawing. For this assignment you will be working on a single python file/program that generates your picture. Here is an example completed picture:

1.   Style

Before you start coding, a few brief comments on style. We've talked about style components in class and now we're going to start utilizing these in your assignments. In particular, make sure you keep the following in mind as you're writing your program:

2.   Prelab

You should use your prelab as a guide to help you as you start to put your picture together. However, feel free to deviate from your original design. The prelab was just a brainstorming session to get you started and to help with the basic layout. As you start to code up your picture, you may also notice that some of your x and y coordinates as well as sizes are not exactly right either because of your measurements or because of a differences in screen size. There are functions in the turtle module that allow you to query the size of the window. Feel free to use these or to just use reasonable values.

3.   Basic Shapes

To get started, we're going to write some functions to make some basic shapes for us. Make sure that you have these working before moving on to the next part. I encourage you to refer to the documentation online as you work on this:    http://docs.python.org/library/turtle.html Don't forget to include the import statement for the turtle module at the top of your file:
from turtle import *

4.   The Background

At this point, you should have two functions written that draw triangles and polygons anywhere on the screen. We'll now work on filling in the background. The key component of the background is randomly spaced circles. Write a function called add_circles that takes as a parameter the number of circles to add and randomly places circles of radius 4 throughout the screen. Some hints for how to do this: To check that everything is working right, try adding differing numbers of circles and make sure that they're distributed throughout the screen and that the right number are actually being drawn. Once you're sure it's working, add a bit more code to make the size of the circles random. You'll have to play with different size ranges to see what looks best. For example, if you look at the picture on the first page of this handout, you'll see that the bubbles range in size. Think about using constants here rather than hard-coding numbers in your code.

5.   Putting it all together

You now have all the components required to put together your final picture. Create a function called generate_picture that draws the entire picture. One way to do this is:
  1. Change the background to the appropriate color.
  2. Change your triangle and polygon functions so that they create filled shapes (see the turtle documentation on how to do this if you don't remember).
  3. Change your add_circles method to also draw filled circles.
  4. Actually create your picture using your three functions. If your design from the prelab is good, this should be fairly painless.
  5. Change the fill color of the objects to make it look more realistic (e.g. orange fish and brown rocks).

6.   Extra Points

You can earn up to 3 extra points on this assignment by including additional elements to your picture. The amount of points given will be assigned based on creativeness and difficulty of implementation. Here are some examples, but I encourage you to include your own: To receive extra points you MUST include in your comments at the top of the program what your extra point additions were (otherwise, it can be hard to figure out sometimes).

Note: If your picture gets very fancy, it is possible that you no longer need the triangle and polygon functions. Even if you don't use them, leave them in your code since they will be graded!

7.   When you're done

When you're all done you should have a working program that draws your picture. Make sure that your program is properly commented: In addition, make sure that you've used good style (named constants, good names for functions, parameters, and variables, white space, etc.)

Digital submission:

Please submit both your program and a screenshot of your picture via the digital submission link on the course home page. Your program should have a ".py" extension; your image should be saved in .png format.

To take a screenshot of the drawing window:

Make sure you submit both your code and your image by the deadline.

8. Grading

                            points
triangle
    equilateral                1
    correct x, y               1
    correct direction          1
polygon
    correct shape              3
    varying sizes              1
    x, y                       1
add_circles
    correct number of circles  1
    covers entire area         1
    random locations           2
    random sizes               1
generate_picture
    background color           1
    proper fills               1
    6+ fish/ships              2
    6+ rocks/planets           2

Prelab                         3
Comments, style                5
Extra points                   3

Total                         27 + 3