""" Author: Sohie Lee Consulted: Date: Spring 2022 Purpose: Lab03, Turtle Functions Filename: turtleStuff.py SOLUTIONS Extra practice """ from turtle import * from turtleBeads import * def logo(size, mainColor): '''Draws a square CS logo with fillcolor mainColor that contains the letters "cs" in bold arial font with fontsize half the size of the square.''' pencolor(mainColor) fillcolor(mainColor) begin_fill() drawSquare(size) end_fill() pencolor('white') # note the integer division because font size must be an integer write('cs', font=('Arial', size//2, 'bold')) def testLogo(): '''Provided test function for logo(). Draws 3 separate cs logos at 3 different locations.''' logo(50, 'red') teleport(200,50) logo(100, 'navy') teleport(-250,-200) logo(300, 'darkslategrey') def bullsEye(size,c1,c2): '''Draws 4 concentric circles from outside in, each circle decreasing in radius by 25%. Initially start with just outlines, fill in later''' pensize(5) # note use of variable, so we don't need to keep recalculating delta = size/4 pencolor(c1) fillcolor(c1) begin_fill() drawCircle(size) end_fill() pencolor(c2) fillcolor(c2) begin_fill() drawCircle(size-delta) end_fill() pencolor(c1) fillcolor(c1) begin_fill() drawCircle(size-2*delta) end_fill() pencolor(c2) fillcolor(c2) begin_fill() drawCircle(size-3*delta) end_fill() def testBullsEye(): '''Testing the bullseye function''' # big one centered bullsEye(400, 'cadetBlue', 'bisque4') teleport(-100, 150) bullsEye(150, 'red','darkSeaGreen3') teleport(100, 300) bullsEye(80, 'black', 'white') teleport(-200, -150) bullsEye(180, 'orange','yellow') teleport(0, -200) bullsEye(80, 'midnightblue', 'lightcyan2') teleport(50, 200) bullsEye(20, 'dodgerBlue3', 'lightpink') teleport(100, -10) bullsEye(120, 'bisque','magenta') def rectFlower(col, width, height): '''Draws a flower with 5 rectangular petals that rotate about the center. Each rectangle has width X height dimensions and is rotated 72 degrees from its neighboring petals.''' pencolor(col) fillcolor(col) # using just one begin_fill and end_fill so that # overlapping areas are filled with white begin_fill() drawRectangle(width, height) lt(72) drawRectangle(width, height) lt(72) drawRectangle(width, height) lt(72) drawRectangle(width, height) lt(72) drawRectangle(width, height) lt(72) end_fill() def testRectFlower(): '''Tests the rectFlower function with 3 invocations.''' rectFlower('orange', 75, 30) teleport(200, 100) rectFlower('navy', 200, 125) teleport(-200, -100) rectFlower('lightCyan2', 200, 34) def bouquet(col, width, height): '''Draws a bouquet of 4 flowers, each at the corner of a square with side length width. Invokes rectFlower. Maintains a position and heading invariant.''' rectFlower(col, width, height) lt(90) leap(width) rectFlower(col, width, height) lt(90) leap(width) rectFlower(col, width, height) lt(90) leap(width) rectFlower(col, width, height) lt(90) leap(width) def pattern1(col, width, height): ''' Draws four bouquets of 4 flowers, each bouquet is at the corner of a squa re with side length width*0.75. Each flower has rectangular petals that are 25% of the width and 25% of the height. Maintains a position and heading invariant. ''' bouquet(col, width/4, height/4) lt(90) leap(width*0.75) bouquet(col, width/4, height/4) lt(90) leap(width*0.75) bouquet(col, width/4, height/4) lt(90) leap(width*0.75) bouquet(col, width/4, height/4) lt(90) leap(width*0.75)