@extends('template')
@section('title')
Lab 2, Part 4: Functions with Python Turtles
@stop
@section('content')
# Lab 2, Part 4: Functions with Python Turtles
Our goal in this part lab is to write a collection of functions that draw using Python's turtles.
Open `lab02/turtleStuff.py` to get started...
## Task 0: CS logo
The CS department needs a new logo and is considering this design.
It would be helpful to see the design in different colors and sizes. To help in this process, you will write a `logo` function.
Your
`logo` function will accept two parameters:
1. `size` - The length of the square
1. `mainColor` - The color of the square
Your `logo` function will write the **lowercase** text "cs" in white, and always in
a font size that is half the square size. For example, if the square has size
30, the font will be size 15. Note that font size must be specified as
an integer. The font will always be bold Arial. `logo` will not return
any values; it merely draws.
Here is an example of how to use the `write` function to draw the lowercase text:
```py
write("I love CS111", font=('Arial',45,'bold'))
```
###How to test your `logo` function?
At the end of your file, paste the following code that invokes your `logo` function.
```py
if __name__ == "__main__":
# test one logo invocation
logo(50, 'red')
```
which produces this drawing:
Notes:
+ Friendly reminder that you can see all [available turtle colors here](colors)
+ If you would like an explanation of the purpose of this main method, see [disabling testing code](/labs/lab02/disablingTests)
Once your `logo` works, you can test it more thoroughly using the provided `testLogo` function in your `lab02/turtleStuff.py` file as follows:
```py
if __name__ == "__main__":
# test one logo invocation
# logo(50, 'red')
testLogo()
```
should yield this drawing:
## Task 1: BullsEye
This `bullsEye` function will draw a circle with radius size that contains 3 nested concentric circles. Each concentric circle will alternate colors and decrease in radius by 25%. Initially, do not fill any circles, keep them just as outlines.
The `bullsEye` function accepts 3 parameters:
1. `size`: the radius of the largest circle
2. `color1`: the color of the outermost and third circle
3. `color2`: the color of the second and fourth circle, counting from the outermost in
Here are two sample invocations:
```py
if __name__ == "__main__":
teleport(-100, 0)
bullsEye(140, 'red','darkOliveGreen')
teleport(100, 200)
bullsEye(80, 'black', 'orange')
```
the create this drawing (note that the pensize is 5 in these drawings):
If these look like your results, then go back to your `bullsEye` function
and fill in each circle, which will then produce this drawing:
And for a more thorough test, run the provided `testBullsEye` function
as follows:
```py
if __name__ == "__main__":
testBullsEye()
```
and it should produce this drawing:
## Task 2: Rectangular flowers
In this task, you'll draw a flower where each of the five "petals" is a rectangle with the specified width and height dimensions. Each "petal" is rotated 72 degrees from its successor (72 x 5 = 360, so the petals are evenly spaced around the flower). Just as above, initially, keep your rectangles as just outlines, we will fill them in with color later.
Write a `rectFlower` function that (initially) takes two parameters:
1. `width`: the width of the rectangular petal
1. `height`: the height of the rectangular petal
Here is a table of some sample invocations:
rectFlower(75, 30) | |
rectFlower(200, 125) | |
rectFlower(200,34) |