In: Computer Science
In Python:
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. This function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degree and moving a given distance 120 times. Calculate the distance moved with the formula 2.0*π*radius/120.0.
code
import turtle
from math import pi
def draw_circle(myTurtle, x, y, radius):
myTurtle.penup()
myTurtle.setposition(x, y-radius) # move to the position x,y-radius where x ,y will be center
myTurtle.pendown()
for i in range(120):
myTurtle.circle(radius, 3)
turtle.getscreen().mainloop()
distance_moved = 2.0*pi*radius/120.0
return distance_moved
myTurtle = turtle.Turtle()
distance = draw_circle(myTurtle, 200,200 ,50)

on console:
2.61799387799
print(distance)