""" Author: Sohie Lee Consulted: Date: Spring 2022 Purpose: Lab03, Fruitful String Functions Filename: cake.py SOLUTIONS """ from turtle import * from turtleBeads import * def cake(height, width, color): ''' Draws a 3-layer cake that decreases 50% in width with each progressive layer. Turtle is in original location when the function is done. Returns total area of all three cake layers. ''' pencolor(color) pensize(5) drawRectangle(width, height) hop(height) drawRectangle(width*.5, height) hop(height) drawRectangle(width * .25, height) hop(height*.75) candle(height/2) hop(-2.75*height) # put turtle back in starting position totalArea = width * height + width * 0.5 * height + width * 0.25 * height return totalArea def candle(height): '''Draws a blue candle with given height and fixed width of 20 ''' pencolor('blue') fillcolor('blue') begin_fill() drawRectangle(20, height) end_fill() hop(height) hop(-height/5) # draw flame pencolor('orange') fillcolor('orange') begin_fill() drawEllipse(height/3, 0.4) end_fill() # return to original position hop(-height) hop(height/5) def cakeRow(height, width): '''Draws a row of 3 cakes, red, green and blue. Each cake has the given height and width. Returns the total area of all cake layers.''' cake1area = cake(height, width, 'red') leap(width) cake2area = cake(height, width, 'green') leap(width) cake3area= cake(height, width, 'blue') leap(-2*width) return cake1area + cake2area + cake3area def shrinkingCakeRow(height, width): '''Draws a row of 3 cakes, red, green and blue. Each cake has 50% smaller width and height of its predecessor. Returns the total area of all cake layers.''' cake1area = cake(height, width, 'red') leap(width/2 + width/4) cake2area = cake(height/2, width/2, 'green') leap(width/4 + width/8) cake3area= cake(height/4, width/4, 'blue') leap(-(width + width/8)) return cake1area + cake2area + cake3area