def main(): try: fps = 50 surface = pygame.display.set_mode((600, 600)) pygame.init() origin = (surface.get_width() / 2, surface.get_height() / 2) theta = 1 step = math.pi / 180 center_x = surface.get_width() / 2 center_y = surface.get_height() / 2 # Cube( surface, color, center3d, size) spheres = ( Fire(surface, pygame.Rect(100, 100, 400, 200), 2), Sphere(surface, (100, 0, 0), Vec3d(-1.5, -1.5, -1.5), Vec3d(1, 1, 1)), # Sphere(surface, (100, 0, 0), Vec3d(0, 0, 0), Vec3d(1, 1, 1)), # Sphere(surface, (100, 0, 0), Vec3d(1.5, 1.5, 1.5), Vec3d(1, 1, 1)), Circle(surface, (100, 0, 0), Vec3d(1.5, -1.5, -1.5), Vec3d(1, 1, 1)), Tree(surface, pygame.Color(0, 100, 100), Vec2d(300, 500), 5, 50), Tree(surface, pygame.Color(0, 100, 100), Vec2d(330, 500), 5, 100), Starfield(surface, stars=100, depth=10), InfoRenderer(surface, pygame.Color(0, 255, 0), pos=Vec2d(100, 100), size=10), ScrollText(surface, "Dolor Ipsum Dolor uswef", 400, pygame.Color(255, 255, 0)), SinusText(surface, "Dolor Ipsum Dolor uswef", 200, 30, 2, pygame.Color(0, 255, 255)), ) clock = pygame.time.Clock() size_angle = 0 size_angle_step = math.pi / 720 cg = ColorGradient(0.0, 0.05, 0.05) background_gradient = GradientBackground(surface) # for 3d projection fov = 2 viewer_distance = 256 pause = False while True: clock.tick(fps) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit(0) keyinput = pygame.key.get_pressed() if keyinput is not None: # print keyinput if keyinput[pygame.K_ESCAPE]: sys.exit(1) # if keyinput[pygame.K_z]: # theta[2] += math.pi / 180 # if keyinput[pygame.KMOD_SHIFT | pygame.K_z]: # theta[2] -= math.pi / 180 # if keyinput[pygame.K_x]: # theta[0] += math.pi / 180 # if keyinput[pygame.KMOD_SHIFT | pygame.K_x]: # theta[0] -= math.pi / 180 # if keyinput[pygame.K_y]: # theta[1] += math.pi / 180 # if keyinput[pygame.KMOD_SHIFT | pygame.K_y]: # theta[1] -= math.pi / 180 if keyinput[pygame.K_UP]: viewer_distance += 1 if keyinput[pygame.K_DOWN]: viewer_distance -= 1 if keyinput[pygame.K_PLUS]: fov += 0.1 if keyinput[pygame.K_MINUS]: fov -= 0.1 if keyinput[pygame.K_p]: pause = not pause if keyinput[pygame.K_r]: viewer_distance = 256 fov = 2 if pause is not True: surface.fill((0, 0, 0, 255)) background_gradient.update() for thing in spheres: if type(thing) == InfoRenderer: thing.update(lines=("viewer_distance : %f" % viewer_distance, "fov: %f" % fov)) continue elif type(thing) == Tree: thing.update() continue elif type(thing) in (Sphere, Circle): # rotate thing.rotate(dx=theta, dy=theta, dz=0.0, offset2d=Vec2d(0, 0)) theta += step * 16 # color changing color = cg.get_color() thing.set_color(color=color) # size wobbling # size_angle += size_angle_step # thing.set_size(0.5 + math.sin(size_angle) * 0.125) # draw thing.update(viewer_distance=viewer_distance, fov=fov) continue elif type(thing) in (SinusText, ScrollText): thing.update() elif type(thing) == Tree: thing.update(center=Vec2d(0, 0), viewer_distance=viewer_distance, fov=fov) else: thing.update() pygame.display.flip() except KeyboardInterrupt: print "shutting down"
def main(): try: fps = 50 surface = pygame.display.set_mode((600, 600)) pygame.init() origin = (surface.get_width() / 2, surface.get_height() / 2) theta = 1 step = math.pi / 180 center_x = surface.get_width() / 2 center_y = surface.get_height() / 2 # Cube( surface, color, center3d, size) spheres = ( Fire(surface, pygame.Rect(100, 100, 400, 200), 2), Sphere(surface, (100, 0, 0), Vec3d(-1.5, -1.5, -1.5), Vec3d(1, 1, 1)), #Sphere(surface, (100, 0, 0), Vec3d(0, 0, 0), Vec3d(1, 1, 1)), #Sphere(surface, (100, 0, 0), Vec3d(1.5, 1.5, 1.5), Vec3d(1, 1, 1)), Circle(surface, (100, 0, 0), Vec3d(1.5, -1.5, -1.5), Vec3d(1, 1, 1)), Tree(surface, pygame.Color(0, 100, 100), Vec2d(300, 500), 5, 50), Tree(surface, pygame.Color(0, 100, 100), Vec2d(330, 500), 5, 100), Starfield(surface, stars=100, depth=10), InfoRenderer(surface, pygame.Color(0, 255, 0), pos=Vec2d(100, 100), size=10), ScrollText(surface, "Dolor Ipsum Dolor uswef", 400, pygame.Color(255, 255, 0)), SinusText(surface, "Dolor Ipsum Dolor uswef", 200, 30, 2, pygame.Color(0, 255, 255)), ) clock = pygame.time.Clock() size_angle = 0 size_angle_step = math.pi / 720 cg = ColorGradient(0.0, 0.05, 0.05) background_gradient = GradientBackground(surface) # for 3d projection fov = 2 viewer_distance = 256 pause = False while True: clock.tick(fps) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit(0) keyinput = pygame.key.get_pressed() if keyinput is not None: # print keyinput if keyinput[pygame.K_ESCAPE]: sys.exit(1) #if keyinput[pygame.K_z]: # theta[2] += math.pi / 180 #if keyinput[pygame.KMOD_SHIFT | pygame.K_z]: # theta[2] -= math.pi / 180 #if keyinput[pygame.K_x]: # theta[0] += math.pi / 180 #if keyinput[pygame.KMOD_SHIFT | pygame.K_x]: # theta[0] -= math.pi / 180 #if keyinput[pygame.K_y]: # theta[1] += math.pi / 180 #if keyinput[pygame.KMOD_SHIFT | pygame.K_y]: # theta[1] -= math.pi / 180 if keyinput[pygame.K_UP]: viewer_distance += 1 if keyinput[pygame.K_DOWN]: viewer_distance -= 1 if keyinput[pygame.K_PLUS]: fov += .1 if keyinput[pygame.K_MINUS]: fov -= .1 if keyinput[pygame.K_p]: pause = not pause if keyinput[pygame.K_r]: viewer_distance = 256 fov = 2 if pause is not True: surface.fill((0, 0, 0, 255)) background_gradient.update() for thing in spheres: if type(thing) == InfoRenderer: thing.update(lines=("viewer_distance : %f" % viewer_distance, "fov: %f" % fov)) continue elif type(thing) == Tree: thing.update() continue elif type(thing) in ( Sphere, Circle, ): # rotate thing.rotate(dx=theta, dy=theta, dz=0.0, offset2d=Vec2d(0, 0)) theta += step * 16 # color changing color = cg.get_color() thing.set_color(color=color) # size wobbling # size_angle += size_angle_step # thing.set_size(0.5 + math.sin(size_angle) * 0.125) # draw thing.update(viewer_distance=viewer_distance, fov=fov) continue elif type(thing) in ( SinusText, ScrollText, ): thing.update() elif type(thing) == Tree: thing.update(center=Vec2d(0, 0), viewer_distance=viewer_distance, fov=fov) else: thing.update() pygame.display.flip() except KeyboardInterrupt: print('shutting down')
def test(): try: fps = 40 surface = pygame.display.set_mode((600, 600)) pygame.init() theta = 1 cubes = ( # Z = -2 Cube(surface, (100, 0, 0), Vec3d(-2, -2, -2), Vec3d(1, 1, 1)), Cube(surface, (100, 100, 0), Vec3d(0, -2, -2), Vec3d(1, 1, 1)), Cube(surface, (200, 100, 0), Vec3d(2, -2, -2), Vec3d(1, 1, 1)), Cube(surface, (0, 200, 0), Vec3d(-2, 0, -2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(0, 0, -2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(2, 0, -2), Vec3d(1, 1, 1)), Cube(surface, (0, 200, 0), Vec3d(-2, 2, -2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(0, 2, -2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(2, 2, -2), Vec3d(1, 1, 1)), # Z = 0 Cube(surface, (100, 0, 0), Vec3d(-2, -2, 0), Vec3d(1, 1, 1)), Cube(surface, (100, 100, 0), Vec3d(0, -2, 0), Vec3d(1, 1, 1)), Cube(surface, (200, 100, 0), Vec3d(2, -2, 0), Vec3d(1, 1, 1)), Cube(surface, (0, 200, 0), Vec3d(-2, 0, 0), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(0, 0, 0), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(2, 0, 0), Vec3d(1, 1, 1)), Cube(surface, (0, 200, 0), Vec3d(-2, 2, 0), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(0, 2, 0), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(2, 2, 0), Vec3d(1, 1, 1)), # Z = 2 Cube(surface, (100, 0, 0), Vec3d(-2, -2, 2), Vec3d(1, 1, 1)), Cube(surface, (100, 100, 0), Vec3d(0, -2, 2), Vec3d(1, 1, 1)), Cube(surface, (200, 100, 0), Vec3d(2, -2, 2), Vec3d(1, 1, 1)), Cube(surface, (0, 200, 0), Vec3d(-2, 0, 2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(0, 0, 2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(2, 0, 2), Vec3d(1, 1, 1)), Cube(surface, (0, 200, 0), Vec3d(-2, 2, 2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(0, 2, 2), Vec3d(1, 1, 1)), Cube(surface, (100, 200, 0), Vec3d(2, 2, 2), Vec3d(1, 1, 1)), ) clock = pygame.time.Clock() size_angle = 0 size_angle_step = math.pi / 720 background_gradient = GradientBackground(surface) while True: clock.tick(fps) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit(0) keyinput = pygame.key.get_pressed() if keyinput is not None: # print keyinput if keyinput[pygame.K_ESCAPE]: sys.exit(1) surface.fill(0) background_gradient.update() for cube in cubes: # rotate cube.rotate(theta, theta, 0.0, Vec2d(0, 0)) theta += 0.1 # size wobbling cube.set_size(0.5 + math.sin(size_angle) * 0.125) size_angle += size_angle_step # draw cube.update() pygame.display.flip() except KeyboardInterrupt: print 'shutting down'