diff --git a/OrbitSim.py b/OrbitSim.py index b3102bd..913c942 100644 --- a/OrbitSim.py +++ b/OrbitSim.py @@ -99,7 +99,8 @@ if __name__=="__main__": resolutionDownscaling = 2 pygame.display.flip() - frameTime = 1/144 #framerate + FPS = 144 #max framerate + frameTime = 1/144 running = True 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) orbitlines = [] renderObjects = [thisEarth, sat, orbitlines] - imageThread = threading.Thread() + clock = pygame.time.Clock() + save = False + clock.tick(FPS) 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(): if event.type == pygame.QUIT: running = False @@ -121,18 +133,9 @@ if __name__=="__main__": camera.renderFrame() pygame.display.flip() else: - #if not imageThread.is_alive(): - #imageThread = threading.Thread(target=camera.renderImage, args=(sat, thisEarth, orbitlines)) - #imageThread.start() - #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) + save = True + + #time.sleep(frameTime) pygame.quit() diff --git a/renderer.py b/renderer.py index cabd0b8..89dadef 100644 --- a/renderer.py +++ b/renderer.py @@ -139,7 +139,7 @@ class Camera: """returns True if camera is inside the planet.""" 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()""" font = pygame.freetype.SysFont("Comic Sans MS", 14) winWidth, winHeight = self.surface.get_size() @@ -212,6 +212,9 @@ class Camera: self.surface.blit(backgroundSurface, (0,0)) self.surface.blit(backSurface, (0,0)) self.surface.blit(frontSurface, (0,0)) + + if save: + pygame.image.save(self.surface, "test.png")