Note on Labelling

The sub-tasks in this section are marked Partner A or Partner B to indicate how to work on them, as in an earlier task of this lab.

Lab 3, Part 3: Turtles like bagels

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

Observations


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


Open lab03/bagel.py to get started...

Function 1: makeOneBagel

Partner B

makeOneBagel accepts the following parameters:

  1. size - The radius of the bagel
  2. outerColor - What color the bagel should be
  3. innerColor - What color the inside of the bagel should be

This function will draw a bagel using the turtle. The bagel hole should be half the radius. When you invoke your makeOneBagel function, you will use the background color as your innercolor so that it looks like a bagel hole.

Test your work by adding a new bagel in your code as follows.

At the end of your file, in the provided test function, add the call to your makeOneBagel function (as well as any helpers):


def test():
    """
    Put all of your testing code in this function. Feel free to modify or
    comment out the tests that are already here.
    """
    print("Start of testing.")
    noTrace()
    # call your function here
    # replace the DESCRIPTIONS_BELOW with your own values
    makeOneBagel(BAGEL_SIZE, OUTERCOLOR, INNERCOLOR)

    showPicture()
    print("Done with testing.")

Friendly reminder that you can see all available turtle colors here (If you would like an explanation of the purpose of this main method, see disabling testing code).

When you run your code, you should see this:

A plate of bagels

Now, add two more bagels to your drawing. It doesn't matter exactly where they go, just make sure they are not overlapping each other.

You can add the lines below to your test function:


   teleport(---, ---)
   # replace the DESCRIPTIONS_BELOW with your own values
   makeOneBagel(BAGEL_SIZE, OUTERCOLOR, INNERCOLOR)

   # move your turtle to a new location for the second bagel
   teleport(---, ---)
   makeOneBagel(BAGEL_SIZE, OUTERCOLOR, INNERCOLOR)

   # move your turtle to a new location for the third bagel
   teleport(---, ---)
   makeOneBagel(BAGEL_SIZE, OUTERCOLOR, INNERCOLOR)

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

Partner A

Add the "bite" to each bagel:

Hints:

  1. The bite should be added only once to your code -- where?
  2. The bite is proportional to the bagel size

Function 2: makeRandomBagel

Here are two built-in python functions that you will use in this task:

Important Note: You must add another import statement to the top of your file:

import random

in order for the random functions to work correctly.

The makeRandomBagel function accepts one parameter, backgroundColor, and will draw a bagel using the turtle. The bagel hole should be half the radius. Your function will use random.randint to select a size in the range between 20 and 200, and random.choice to select a color from a set of four colors that you select from this colors list.

You can add this snippet of code to your test function.

    teleport(0,100)
    makeRandomBagel('white')
    teleport(150, 300)
    makeRandomBagel('white')
    teleport(-100,-150)
    makeRandomBagel('white')

Executing that snippet 3 different times generates 3 different images:

3 randomly-colored and randomly-sized bagels 3 randomly-colored and randomly-sized bagels 3 randomly-colored and randomly-sized bagels

[OPTIONAL] Function 3: Add some random seeds to your [everything] bagel*

*Hat tip to Maxine Aguilar and Taylor Balfour for this idea

Partner B

Here are some randomly placed "seeds" on each bagel:

Hints:

  1. Write one function to return one randomly placed seed
  2. Here's a function you can use: random.randint. For example, random.randint(1, 10) returns a randomly selected integer between 1 and 10, inclusive.
  3. The images above show 5 seeds added to each bagel (where in your code should you add the seeds to your bagel?)
  4. Ideally, seeds should only appear on the body of the bagel, but its ok if yours appear in the "hole"
  5. Later in the semester, we will learn a better way of adding a whole bunch of seeds (repeating a block of code)

Table of Contents