GooberDoo
GooberDoo

Reputation: 21

Why is my circle program rotating the turtle twice before finishing

When I try to run this code it works but the turtle rotates twice. I have tried looking for a limiter line or something but couldn't find anything.

import turtle
import math

def drawCircle():
    rad = int(input("Insert your radius : "))
    cent = int(input("Insert center point : "))
    circle = turtle.Turtle()
    circle.up()
    circle.goto(cent,rad)
    circle.down()    
    circle.color("black")
    times_crossed_y = 0
    x_sign = 1.0
    while times_crossed_y <= 3:
        circle.forward(2 * math.pi * rad / 120.0)
        circle.right(3.0)
        x_sign_new = math.copysign(1, circle.xcor())        
        if(x_sign_new != x_sign):
            times_crossed_y += 1
        x_sign = x_sign_new
    return  
drawCircle()
print("Finished")
turtle.done()

Upvotes: 1

Views: 88

Answers (1)

3NiGMa
3NiGMa

Reputation: 545

The line that says while times_crossed_y <= 3: should be while times_crossed_y <= 1:, change your code to this;

import turtle
import math

def drawCircle():
    rad = int(input("Insert your radius : "))
    cent = int(input("Insert center point : "))
    circle = turtle.Turtle()
    circle.up()
    circle.goto(cent,rad)
    circle.down()    
    circle.color("black")
    times_crossed_y = 0
    x_sign = 1.0
    while times_crossed_y <= 1:
        circle.forward(2 * math.pi * rad / 120.0)
        circle.right(3.0)
        x_sign_new = math.copysign(1, circle.xcor())        
        if(x_sign_new != x_sign):
            times_crossed_y += 1
        x_sign = x_sign_new
    return  
drawCircle()
print("Finished")
turtle.done()

Upvotes: 1

Related Questions