@extends('template')
@section('title')
Lab 3, Turtle Cake Baking
@stop
@section('content')
# Lab 3 Bonus: Turtle Cake Baking (Functions with Python Turtles)
Our goal in this part of the lab is to write a collection of fruitful
functions that draw cakes using Python's turtles.
Open `lab03/cake.py` to get started.
## Task 1: Two layer cake
`cake(75, 200, 'blue'')` draws this cake and should return __22500__:
A few notes about the `cake` function:
+ Note that the turtle always returns to its initial starting position at the end of the function. Make sure any edits that you make to this function still ensure that the turtle is back in its original position before the function was called.
+ Right now, the `cake` function always returns 0. You will change this to calculate the total area of the two cake layers, and return that value from your `cake` function. The areas for the two cakes above are shown.
+ Why should the red cake above return 48000? The bottom layer has dimensions 80 x 400, which has area 32000. The top layer has dimensions 80 x 200, which as area 16000. 32000 + 16000 = 48000.
###How to test?
You can test the `cake` function in the Shell. Here are two examples.
_Hint_: if you see overlapping cakes in your Turtle canvas, you can use `setupTurtle()` to clear the canvas between calls to your `cake` function (as shown above).
## Task 2: Three layer cake with a candle
`cake(75, 200, 'blue'')` draws this cake and should return __26250__:
__Task 2A:__ Draw the third cake layer, and make sure your turtle is back in its
original starting position when done. You'll know because you'll see the turtle in
the center of the bottom cake layer.
__Task 2B:__ Re-calculate the total area of the cake by adding in the area of the
third layer. Check that your `cake` function returns the numbers shown above. Note we are not counting the area of the candle, only the area of the cake layers.
__Task 2C:__ Add the candle to your third cake layer. You are given the `candle` function which draws a blue candle with an orange flame. You specify the height of the candle; its width is fixed at 20. Here are two invocations of the candle function:
| candle(45) | candle(100) |
|
|
`cakeRow(70, 100)` draws these cakes and should return __36750__:
Check that your `cakeRow` function returns the turtle to its starting position (centered in the bottom layer of the leftmost cake).
## Task 4: A triplet of diminishing three-layer cakes
`shrinkingCakeRow(40, 100)` draws these cakes and should return __9187.5__:
Note:
+ Check that your `shrinkingCakeRow` function returns the turtle to its starting position (centered in the bottom layer of the leftmost cake).
+ Note how the cakes are no longer aligned on the bottom edge
+ Note that the fixed candle width of 20 is too wide for the shrinking cakes when the first width is 100 or less.
##Yay, you made it to the end of the lab!
If you still have time left, there are some optional exercises you could
work on:
- [More turtle drawing](turtleFunctions) will give more practice using
parameters and writing turtle functions.
- [Knowledge check](check) linked at the bottom of the page in the Table of Contents. Take this fun quiz to check your knowledge.
@include('/labs/lab03/_toc')
@stop