15,749,281 members
See more:
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? "))

win = GraphWin (winName, 500, 500)

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

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

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

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

for i in range(5):
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()```

What I have tried:

I have tried many different math formulas to try and get different values that could be useful but none seem to work.
Posted
Updated 21-Sep-22 20:49pm

## Solution 1

5 values are not enough to draw a circle: they draw a rough pentagram (ish) and will only approximate a circle for tiny radii.

Change the range(5) to a higher value - 100 or so, and increase theta by 2π / 100 each time round the loop (2π radians is 360o so the angle needs to change through the whole 2π radian range for a complete circle).

The exact number or points you need to plot will depend on the radius of the circle: the bigger it is the more points you need to get a smooth surface.

CPallini 22-Sep-22 2:34am
5.

## Solution 2

You could start using simple constant values, in order to better understand what is happening.
Try, for instance
Python
```from graphics import *
import math

def main():

winName = "circles"
win = GraphWin (winName, 500, 500)

color1 = "red"
x1 = 250
y1 = 250

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

color2 = "green"
x2 = x1

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

phi = 0
while phi < 2*math.pi:
dx = nx-x2
dy = ny-y2
x2 = nx
y2 = ny
circ2.move(dx,dy)
phi = phi+math.pi/100
time.sleep(.1)

main()```