Having trouble getting an object to move in a circle

Viewed 26

With what I currently have, my circle just flies away in a straight line. I'm trying to get the circle to spin around the other circle but the circular movement just isn't happening. I am very new to coding. Thank you in advance!

from graphics import *

def main():
    winName = input ("What would you like the name of the window to be? ")
    color1 = input("What color would you like the circle to be? ")
    x1, y1 = eval(input("What are the x, y coordinates of the center of the circle? "))
    radius1 = eval(input("What is the radius of the circle? "))

    win = GraphWin (winName, 500, 500)

    center1 = Point (x1, y1)
    circ1 = Circle (center1, radius1)
    circ1.setFill (color1)
    circ1.draw (win)

    color2 = ('green')
    x2 = x1
    y2 = y1 - (2 * radius1)
    radius2 = radius1 * (1/2)

    center2 = Point (x2, y2)
    circ2 = Circle (center2, radius2)
    circ2.setFill (color2)
    circ2.draw (win)

    line = Line (center1, center2)
    line.setFill('red')
    line.draw(win)

    for i in range(5):
        hyp = radius1 * 2
        leg = x2 - x1
        theta = math.acos(leg/hyp)
        circ2.move(x1 + (math.cos(theta) * (radius1 * 2)), y1 + (math.sin(theta) * (radius1 * 2)))
        line.undraw()
        time.sleep(1)

    newCenter = (circ2.getCenter(), center1)

    line = Line(circ2.getCenter(), center1)
    line.setFill('red')
    line.draw(win)

main()
0 Answers
Related