def run(): window_surface = pygame.display.set_mode((400, 400)) sphere = Sphere(Point(0, 0, 0), radius=1.) view_point = ViewPoint(Point(0, 0, -5.1)) pixels = pygame.PixelArray(window_surface) image = Image(Rectangle(Point(-1, -1, -4.1), Vector(0.005, 0., 0.), Vector(0, 0.005, 0.)), pixels) ray_generator = RayGenerator(view_point, image) rays = ray_generator.generate() theta, phi = 0. , 0. light_source = LightSource(Vector(math.sin(theta)*math.cos(phi), math.sin(theta)*math.sin(phi), math.cos(theta)), 0.5) ray_intersector = RaySphereIntersector(sphere, view_point.point().as_vector()) ray_shader = RayShader() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: theta += 0.1 if event.key == pygame.K_UP: theta -= 0.1 if event.key == pygame.K_LEFT: phi -= 0.1 if event.key == pygame.K_RIGHT: phi += 0.1 window_surface.fill((0, 0, 0,)) draw(rays, ray_intersector, ray_shader, light_source, sphere, image) light_source = LightSource( Vector(math.sin(theta) * math.cos(phi), math.sin(theta) * math.sin(phi), math.cos(theta)), 0.5) pygame.display.flip() print("theta " + str(theta)) print("phi " + str(phi)) print(" ")