In: Computer Science
Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. The function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degrees and moving a given distance 120 times. Calculate the distance moved with the formula 2.0 × π × radius ÷ 120.0.
Define a function main that will draw a circle with the following parameters when the program is run:
Code:
import turtle
def drawCircle(turtle, x, y, radius):
turtle.penup()
#setting the given co-ordinates (50,75)
turtle.setposition(x, y)
#turns 3 degree
turtle.left(3)
#moving forward 120 times
turtle.forward(120)
turtle.pendown()
#drawing the circle of given radius 100
turtle.circle(radius)
turtle.getscreen()._root.mainloop()
#printing the distance moved
print("Distance Moved:",((2 * 3.14 * radius ) / 120))
turt= turtle.Turtle()#turtle object
x = 50
y = 75
radius = 100#declaring variables
drawCircle(turt, x, y, radius)
#calling the function
Output:
Indentation: