@extends('template')
@section('title')
Lab 3, Part 3: Turtles like bagels
@stop
@section('content')
## 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](happy-owls).
# 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
+ What are the common characteristics of a bagel?
+ What are the characteristics that differ for each bagel? (These will be your parameters!)
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
1. `outerColor` - What color the bagel should be
2. `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):
```py
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](/labs/lab01/colors) (If you would like an explanation of the purpose of
this main method, see [disabling testing code](/labs/lab02/disablingTests)).
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:
```py
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:
* `random.randint`: returns a random integer between `a` and `b`, inclusive. For example,
```py
random.randint(1,6) # returns a random integer between 1-6, inclusive
random.randint(50,100) # returns a random integer between 50-100, inclusive
```
* `random.choice`: returns a randomly chosen item from the given list
```py
random.choice(['red','orange','yellow','blue']) # returns a random color
random.choice(['Jimin','RM','Jungkook','Jin','V','Suga','J-Hope']) # returns a random name
random.choice([4.3, 5.9, 3.14, 2.01]) # returns a random number
```
Note the square brackets `[ ]` tucked inside the parentheses of `random.choice`. This is a symbol that python recognizes as grouping the set of items together.
**Important Note**: You must add another import statement to the top of your file:
```py
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](/labs/lab01/colors).
You can add this snippet of code to your `test` function.
```py
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:
## [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
0. 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.
2. The images above show 5 seeds added to each bagel (where
in your code should you add the seeds to your bagel?)
3. Ideally, seeds should only appear on the body of the bagel, but
its ok if yours appear in the "hole"
4. Later in the semester, we will learn a better way of adding a
whole bunch of seeds (repeating a block of code)
@include('/labs/lab03/_toc')
@stop