2010 January 8 / j d a v i s @ c a r l e t o n . e d u

Assignment 3: Drawing Circles

The purpose of this assignment is to practice writing Python functions. You may complete the assignment with one partner, or alone if you prefer. It must be handed in electronically by the start of class on Monday.

You will write a program to draw concentric circles, in a file concentric.py. The most important part of your program is a function called drawCircleHere(). The function takes in two inputs: a turtle and a radius. That is, the first line of the function is

def drawCircleHere(turtle, radius):

The function uses the turtle to draw a circle of the given radius, centered at the turtle's current position. Furthermore, at the end of the function the turtle's position and heading are restored to what they were before the function was invoked.

This drawCircleHere() function is similar to the drawCircle() function from Chapter 1 of our textbook. If you haven't read that part of Chapter 1 yet, you should. The difference is that drawCircleHere() draws a circle centered at the current position, whereas drawCircle() draws a circle centered at a point somewhere to the right of the current position.

A clever student will realize that drawCircleHere() doesn't need to be written from scratch; he will just copy drawCircle()'s code and make modifications. But a really clever student will go one step further; she will copy drawCircle(), leave it unmodified, and invoke drawCircle() from within drawCircleHere(). You are required to do the latter. That is, your drawCircleHere() must call upon drawCircle() to do its drawing. Because you are using drawCircle(), you have to copy it into your program. Be sure to understand how it works. On what other functions and modules does it rely?

Once you have written drawCircleHere(), use it to draw a single picture consisting of concentric circles of radii 50, 70, 90, 110, and 130. Use the raw_input() trick from Getting Started with Python to keep your window open, so that the user of your program has a chance to inspect your artwork.

Here is a skeleton for your program file concentric.py. There are two places marked, where you have to insert some code; you may have to insert code in other places, too.

import cTurtle

def drawCircle(turtle, radius):
    circumference = 2 * 3.1415 * radius
    sideLength = circumference / 360
    drawPolygon(turtle, sideLength, 360)

def drawCircleHere(turtle, radius):
    # !! you have to write some stuff here

gertrude = cTurtle.Turtle()
# !! write some more stuff here
raw_input("Press Return to exit.")

Hand in concentric.py electronically, as you did in Assignment 2. Your work will be graded according to these criteria: