import
pygame
import
math
pygame.init()
width
=
1000
height
=
600
screen_res
=
(width, height)
pygame.display.set_caption(
"GFG Elliptical orbit"
)
screen
=
pygame.display.set_mode(screen_res)
red
=
(
255
,
0
,
0
)
green
=
(
0
,
255
,
0
)
blue
=
(
0
,
0
,
255
)
cyan
=
(
0
,
255
,
255
)
X_center
=
width
/
/
2
Y_center
=
height
/
/
2
X_ellipse
=
400
Y_ellipse
=
225
clock
=
pygame.time.Clock()
while
True
:
for
degree
in
range
(
0
,
360
,
1
):
for
event
in
pygame.event.get():
if
event.
type
=
=
pygame.QUIT:
exit()
screen.fill([
0
,
0
,
0
])
x_planet_1
=
int
(math.cos(degree
*
2
*
math.pi
/
360
)
*
X_ellipse)
+
X_center
y_planet_1
=
int
(math.sin(degree
*
2
*
math.pi
/
360
)
*
Y_ellipse)
+
Y_center
degree_2
=
degree
+
180
if
degree >
180
:
degree_2
=
degree
-
180
x_planet_2
=
int
(math.cos(degree_2
*
2
*
math.pi
/
360
)
*
X_ellipse)
+
X_center
y_planet_2
=
int
(math.sin(degree_2
*
2
*
math.pi
/
360
)
*
Y_ellipse)
+
Y_center
pygame.draw.circle(surface
=
screen, color
=
red, center
=
[
X_center, Y_center], radius
=
60
)
pygame.draw.ellipse(surface
=
screen, color
=
green,
rect
=
[
100
,
75
,
800
,
450
], width
=
1
)
pygame.draw.circle(surface
=
screen, color
=
blue, center
=
[
x_planet_1, y_planet_1], radius
=
40
)
pygame.draw.circle(surface
=
screen, color
=
cyan, center
=
[
x_planet_2, y_planet_2], radius
=
40
)
clock.tick(
5
)
pygame.display.flip()