Showing posts with label simulate elliptical orbit in pygame. Show all posts
Showing posts with label simulate elliptical orbit in pygame. Show all posts

Algorithm - Simulation of Elliptical Orbit

Algorithm - Simulation of Elliptical orbit
  1.     Start the program
  2.     Set screen size and caption
  3.     Create clock variable
  4.     Set x and y radius of ellipse.
  5.     Starting from degree 0 ending with 360 degrees in increments of 10 degrees  calculate the (x1, y1) coordinates to find a point in the elliptical orbit.
  6.     Convert degree to radians (degree * 2 * math.pi / 360)
  7.     Set background color, draw center circle, ellipse and another smaller circle on the ellipse
  8.     Refresh the screen every 5 clock ticks
  9.     Repeat steps 4 to 8 until user quits the program
  10.     Stop the program


Simulate Elliptical Orbit in Pygame

#Elliptical orbits

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)


Algorithmhttps://drranurekha.blogspot.com/2019/10/algorithm-simulation-of-elliptical-orbit_58.html



Output: