Lab 2: Turtles like bagels

Our goal in this part of today's lab is to create scenes of yummy bagels like the following:

Four circles on a blue background, each with a hole in the middle. Each one is a different size and color from the others.

Observations


To accomplish this task, we'll create a function that will draw a bagel and we'll call it makeOneBagel.


Open the provided file lab02/bagels.py to get started...

Function 1: makeOneBagel

Partner A

makeOneBagel accepts the following parameters:

  1. size - The radius of the bagel circle
  2. color - What color the bagel should be

This function will draw a bagel using the turtle by setting a thick pen size and drawing a circle using drawCircle. The circle radius should be the given size, and the pen thickness should be 1/2 of that size.

To start with, create a definition for makeOneBagel in your bagels.py file, and then write the docstring for this function that describes what it will do. After you've explained our plan, you are ready to write the code.

Write your code for makeOneBagel, and then test your work by first running the file (which defines your function) and then pasting this code into the shell:

makeOneBagel(60, 'tomato3')

When you hit enter, you should see a bagel like this:

A single orange-red bagel on a blue background. The bagel is drawn as a thick circle with an open center.

Friendly reminder: you can see all available turtle colors here

A plate of bagels

Now, open the provided file test_bagels.py. This is a testing file that will import your bagels file and test the functions in it. It comes with code for drawing four bagels, and if you run it, you should see this:

The same image of four bagels from the start of this lab.

Hungry, huh? Someone took a bite out of the bagel!

Partner B

Define a new function called makeBittenBagel which draws a bagel, but then takes a bite out of it. This function will need one extra parameter to tell it what the background color is.

Here's what the bitten bagel looks like:

Hints:

  1. You can use makeOneBagel from within makeBittenBagel to do a lot of the work.
  2. To "erase" part of the bagel, just draw a filled circle on top that's the same color as the background.
  3. The bite is proportional to the bagel size: it always bites halfway through the bagel.

There is a line of code in test_bagels.py which is commented out with a # that calls makeBittenBagel. Uncomment that line, and comment out the call to makeOneBagel above it so that you can replace one of your four test bagels with a bitten bagel.

That's it!

Congratulations, you made it to the end of the lab!

If you still have time left, there are some optional exercises you could work on:

Table of Contents