Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Look at the function to calculate the next y - position for drawing a set of shapes. This function is called near the bottom of
Look at the function to calculate the next yposition for drawing a set of shapes. This function is called near the bottom of the program: # Draws sets of shapes of related sizes
# Draw a rectangle
# Draw a triangle with sides the same size as rectangle length
# Draw a filled circle with the same area as the rectangle
# Draw a triangle with the same area as the rectangle
# Draw a filled circle with the same diameter as the previous triangle side
import turtle
import math
def nextypositionyht:
Returns the next yposition, given current position y and height ht
next y ht
return next
def drawRectt len, wid:
Draws a rectangle using turtle t with sides len and wid
for side in len wid, len, wid:
tforwardside
tleft
def drawFilledCirclet rad:
Draws a filled circle of radius rad using turtle t
tbeginfill
tcirclerad
tendfill
def main:
# named constants
screensize
screenstartx # x coordinate of the left edge of the graphics window
# Set up the window and its attributes
wn turtle.Screen
wnsetupscreensize, screensize, screenstartx,
wnbgcoloryellow
axel turtle.Turtle
axel.speed
# Initial turtle position near left edge, toward the bottom
xpos screensize
ypos screensize
axel.up
axel.gotoxposypos
axel.down
# ydimension of each rectangle
width
# draw three sets of shapes same widthydimension but different lengths
for length in :
# Draw the rectangle
drawRectaxel length, width
# Here's code to draw a rectangle before putting in a function
#for side in length width, length, width:
#axel.forwardside
#axel.left
# Draw an equilateral triangle with sides the same as rectangle length
for in range:
axel.forwardlength
axel.left
# Move a little to the right of the rectangle
axel.up
axel.forwardlength
axel.down
# Draw a circle with the same area as the rectangle
radius math.sqrtlengthwidthmathpi
drawFilledCircleaxel radius
#axel.beginfill
#axel.circleradius
#axel.endfill
# Move a little to the right of the circle
axel.up
axel.forwardradius
axel.down
# Draw an equilateral triangle with same area as rectangle
triside math.sqrtlengthwidthmathsqrt
for in range:
axel.forwardtriside
axel.left
# Move a little to the right of the triangle
axel.up
axel.forwardtriside
axel.down
# Draw a circle with the same diameter as the triangle side
axel.beginfill
axel.circletriside
axel.endfill
# Calculate the next vertical position for a set of shapes
ypos nextypositionypos triside
# Put turtle to left side of screen at correct height
axel.up
axel.gotoxposypos
axel.down
# Close window nicely after loop finishes
wnexitonclick
# Run the main function. This should be the last statement in the file.
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started