Python Turtle end in the center of a circle

Viewed 22

I am wondering how I can get the pointer to end in the center of the circle. It is okay if there is a line drawn to the center of the circle.

radius = int(input("Enter the radius"))
circum = 2*3.1416 * radius 
number_of_sides = 50
side_length = circum / number_of_sides
angle = 360 / number_of_sides
import turtle

circle =turtle.Turtle()
for i in range (number_of_sides):
    circle.color("red")
    circle.forward(side_length)
    circle.left(angle)
1 Answers

Here's an example where the circle is drawn around the axis origin and the turtle is moved to the origin (home()) once it's drawn:

from turtle import Screen, Turtle
from math import pi

NUMBER_OF_SIDES = 50

radius = float(input("Enter the radius: "))

circumference = 2 * pi * radius
side_length = circumference / NUMBER_OF_SIDES
angle = 360 / NUMBER_OF_SIDES

screen = Screen()

turtle = Turtle()
turtle.color("red")
turtle.dot()  # indicate the origin

turtle.penup()
turtle.sety(-radius)
turtle.pendown()

for _ in range(NUMBER_OF_SIDES):
    turtle.left(angle/2)  # make result match turtle.circle()
    turtle.forward(side_length)
    turtle.left(angle/2)

turtle.penup()
turtle.home()

screen.exitonclick()
Related