#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)
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)
It would be better if you could explain the program step by step
ReplyDeletesure
ReplyDelete# setting screen size and caption
screen = pygame.display.set_mode((600, 300))
pygame.display.set_caption("Elliptical orbit")
# creating clock variable
clock = pygame.time.Clock()
# until closing the display screen
while(True):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# setting x and y radius of ellipse.
xRadius = 250
yRadius = 100
'''
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
x1 = cos(radians) * xradius of ellipse
first convert degree to radians (degree * 2 * math.pi / 360)
x1 = (type conversion-int)(math.cos(radians) * xradius) + screensize/2
'''
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
# set background color, draw center circle, ellipse and another smaller circle on the ellipse
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)
# refresh the screen every 5 clock ticks
pygame.display.flip()
clock.tick(5)
you can change the screen size by altering the values of width(600) and height(300)
ReplyDeletescreen = pygame.display.set_mode((600, 300))
ReplyDeletepygame.draw.circle(screen, (255, 0, 0), [300, 150], 35)
Note:
screen = pygame.display.set_mode((600, 300))
pygame.draw.circle(screen, (color of circle), [x, y coordinates], radius of circle)
clock.tick(5)
ReplyDeletemodify the speed by changing the clock tick
Traceback (most recent call last):
ReplyDeleteFile "C:/Python32/gui1.py", line 2, in
import pygame
File "C:\Python32\lib\pygame\__init__.py", line 141, in
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
check if you have compatible version of python and pygame.
Deletepygame-1.9.2a0.win32-py3.2
python-3.2
Note:
mine is 32 bit. check your system configuration
Happy programming...
Anu
try and tell me if it works
Deletethanks
Anu
my python version is 3.7.3
Deletethen i installed pygame-1.9.2a0.win32-py3.2
still it is showing trace back error like
Traceback (most recent call last):
File "C:/PYTHON/pg.py", line 3, in
import pygame
ModuleNotFoundError: No module named 'pygame'
please solve my problem
You need compatible versions of python and pygame. ur pygame is 3.2 and python is 3.7. wont work.
DeleteTraceback (most recent call last):
ReplyDeleteFile "C:/Python27/ellip.py", line 7, in
screen = pygame.display.set_mode((600, 300))
error: No available video device
Im getting this error...
check
Deleteimport sys line
Iam also getting error. and yes I have checked import sys line
DeleteFile "", line 24
screen.fill((0, 0, 0))
^
IndentationError: unexpected indent
yours is an indentation error. not in import.
Deletescreen.fill((0,0,0)) should be in same indent as previous lines within the for loop.
Thankyou mam helped a lot on exams
ReplyDeletei need algorithm for that simulation program of elliptical orbit in pygame
ReplyDeletehttps://drranurekha.blogspot.com/2019/10/algorithm-simulation-of-elliptical-orbit_58.html
DeleteI NEED ALGORITHM MAM
ReplyDeleteThanks for the extremely helpful information!
ReplyDeleteHow to import the module for begining
ReplyDelete