switched to pygame clock management; added flag to save frame to disk
This commit is contained in:
parent
d521f3d0a3
commit
8d53f693fd
31
OrbitSim.py
31
OrbitSim.py
|
@ -99,7 +99,8 @@ if __name__=="__main__":
|
||||||
resolutionDownscaling = 2
|
resolutionDownscaling = 2
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
frameTime = 1/144 #framerate
|
FPS = 144 #max framerate
|
||||||
|
frameTime = 1/144
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
display = False
|
display = False
|
||||||
|
@ -107,10 +108,21 @@ if __name__=="__main__":
|
||||||
sat = OrbitingBody(Point(0, config()["earthRadius"] + 2042000, config()["earthRadius"] + 3000000), Point(-4800,0,-1800), "BoSLOO", 5, thisEarth)
|
sat = OrbitingBody(Point(0, config()["earthRadius"] + 2042000, config()["earthRadius"] + 3000000), Point(-4800,0,-1800), "BoSLOO", 5, thisEarth)
|
||||||
orbitlines = []
|
orbitlines = []
|
||||||
renderObjects = [thisEarth, sat, orbitlines]
|
renderObjects = [thisEarth, sat, orbitlines]
|
||||||
imageThread = threading.Thread()
|
clock = pygame.time.Clock()
|
||||||
|
save = False
|
||||||
|
|
||||||
|
clock.tick(FPS)
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
|
clock.tick(FPS)
|
||||||
|
if display:
|
||||||
|
#deltaTime = frameTime * config()["timeScale"]
|
||||||
|
deltaTime = (clock.get_time()/1000) * config()["timeScale"]
|
||||||
|
physicsUpdate(renderObjects, orbitlines, deltaTime)
|
||||||
|
camera.renderFrame(save=save)
|
||||||
|
save=False
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
|
@ -121,18 +133,9 @@ if __name__=="__main__":
|
||||||
camera.renderFrame()
|
camera.renderFrame()
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
else:
|
else:
|
||||||
#if not imageThread.is_alive():
|
save = True
|
||||||
#imageThread = threading.Thread(target=camera.renderImage, args=(sat, thisEarth, orbitlines))
|
|
||||||
#imageThread.start()
|
#time.sleep(frameTime)
|
||||||
#display = False
|
|
||||||
#window.fill((0,0,0))
|
|
||||||
pygame.display.flip()
|
|
||||||
if display:
|
|
||||||
deltaTime = frameTime * config()["timeScale"]
|
|
||||||
physicsUpdate(renderObjects, orbitlines, deltaTime)
|
|
||||||
camera.renderFrame()
|
|
||||||
pygame.display.flip()
|
|
||||||
time.sleep(frameTime)
|
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ class Camera:
|
||||||
"""returns True if camera is inside the planet."""
|
"""returns True if camera is inside the planet."""
|
||||||
return numpy.linalg.norm(self.location.magnitude) < planet.radius
|
return numpy.linalg.norm(self.location.magnitude) < planet.radius
|
||||||
|
|
||||||
def renderFrame(self):
|
def renderFrame(self, save=False):
|
||||||
"""generates a frame and draws it to the surface. Does not update screen; use pygame.display.flip()"""
|
"""generates a frame and draws it to the surface. Does not update screen; use pygame.display.flip()"""
|
||||||
font = pygame.freetype.SysFont("Comic Sans MS", 14)
|
font = pygame.freetype.SysFont("Comic Sans MS", 14)
|
||||||
winWidth, winHeight = self.surface.get_size()
|
winWidth, winHeight = self.surface.get_size()
|
||||||
|
@ -213,6 +213,9 @@ class Camera:
|
||||||
self.surface.blit(backSurface, (0,0))
|
self.surface.blit(backSurface, (0,0))
|
||||||
self.surface.blit(frontSurface, (0,0))
|
self.surface.blit(frontSurface, (0,0))
|
||||||
|
|
||||||
|
if save:
|
||||||
|
pygame.image.save(self.surface, "test.png")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def renderImage(self, sat:"OrbitingBody", planet:"Planet", points):
|
def renderImage(self, sat:"OrbitingBody", planet:"Planet", points):
|
||||||
|
|
Loading…
Reference in a new issue