0% found this document useful (0 votes)
42 views1 page

Import Pygame

This Python code uses the Pygame library to simulate an elliptical orbit by drawing an ellipse, a central point, and a moving point that follows an elliptical path around the central point. It initializes Pygame, sets up a display screen and clock, then loops through degrees from 0 to 360, calculating the x and y coordinates of the moving point based on its position along the ellipse's orbit. It draws the ellipse, central point, and moving point on each iteration before updating the display.

Uploaded by

Sanjit Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views1 page

Import Pygame

This Python code uses the Pygame library to simulate an elliptical orbit by drawing an ellipse, a central point, and a moving point that follows an elliptical path around the central point. It initializes Pygame, sets up a display screen and clock, then loops through degrees from 0 to 360, calculating the x and y coordinates of the moving point based on its position along the ellipse's orbit. It draws the ellipse, central point, and moving point on each iteration before updating the display.

Uploaded by

Sanjit Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import pygame

import math
import sys

pygame.init()

screen = pygame.display.set_mode((600, 300))


pygame.display.set_caption("Elliptical orbit")

clock = pygame.time.Clock()

while (True):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()

xRadius = 250
yRadius = 100

for degree in range(0, 360, 10):


x1 = int(math.cos(degree * 2 * math.pi / 360) * xRadius) + 300
y1 = int(math.sin(degree * 2 * math.pi / 360) * yRadius) + 150
screen.fill((0, 0, 0))
pygame.draw.circle(screen, (255, 0, 0), [300, 150], 35)
pygame.draw.ellipse(screen, (255, 255, 255), [50, 50, 500, 200], 1)
pygame.draw.circle(screen, (0, 0, 255), [x1, y1], 15)

pygame.display.flip()
clock.tick(5)

You might also like