Answered step by step
Verified Expert Solution
Link Copied!

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 y-position for drawing a set of shapes. This function is called near the bottom of the program: # Draws 3 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 next_y_position(y,ht):
""" Returns the next y-position, given current position y and height ht """
next = y + ht +30
return next
def drawRect(t, len, wid):
""" Draws a rectangle using turtle t with sides len and wid """
for side in [len, wid, len, wid]:
t.forward(side)
t.left(90)
def drawFilledCircle(t, rad):
""" Draws a filled circle of radius rad using turtle t """
t.begin_fill()
t.circle(rad)
t.end_fill()
def main():
# named constants
screen_size =500
screen_startx =60 # x coordinate of the left edge of the graphics window
# Set up the window and its attributes
wn = turtle.Screen()
wn.setup(screen_size, screen_size, screen_startx, 0)
wn.bgcolor("yellow")
axel = turtle.Turtle()
axel.speed(7)
# Initial turtle position near left edge, toward the bottom
xpos =-screen_size/2+20
ypos =-screen_size/2+50
axel.up()
axel.goto(xpos,ypos)
axel.down()
# y-dimension of each rectangle
width =50
# draw three sets of shapes - same width(y-dimension) but different lengths
for length in [25,55,75]:
# Draw the rectangle
drawRect(axel, length, width)
# Here's code to draw a rectangle - before putting in a function
#for side in [length, width, length, width]:
#axel.forward(side)
#axel.left(90)
# Draw an equilateral triangle with sides the same as rectangle length
for _ in range(3):
axel.forward(length)
axel.left(120)
# Move a little to the right of the rectangle
axel.up()
axel.forward(2*length)
axel.down()
# Draw a circle with the same area as the rectangle
radius = math.sqrt(length*width/math.pi)
drawFilledCircle(axel, radius)
#axel.begin_fill()
#axel.circle(radius)
#axel.end_fill()
# Move a little to the right of the circle
axel.up()
axel.forward(2*radius)
axel.down()
# Draw an equilateral triangle with same area as rectangle
tri_side = math.sqrt(length*width*4/math.sqrt(3))
for _ in range(3):
axel.forward(tri_side)
axel.left(120)
# Move a little to the right of the triangle
axel.up()
axel.forward(2*tri_side)
axel.down()
# Draw a circle with the same diameter as the triangle side
axel.begin_fill()
axel.circle(tri_side/2)
axel.end_fill()
# Calculate the next vertical position for a set of shapes
ypos = next_y_position(ypos, tri_side)
# Put turtle to left side of screen at correct height
axel.up()
axel.goto(xpos,ypos)
axel.down()
# Close window nicely after loop finishes
wn.exitonclick()
# 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 17th International Conference Dasfaa 2012 Busan South Korea April 2012 Proceedings Part 1 Lncs 7238

Authors: Sang-goo Lee ,Zhiyong Peng ,Xiaofang Zhou ,Yang-Sae Moon ,Rainer Unland ,Jaesoo Yoo

2012 Edition

364229037X, 978-3642290374

More Books

Students also viewed these Databases questions