def test_lighting_with_pattern(self):
     m = Material()
     m.pattern = Stripe(Color(1, 1, 1), Color(0, 0, 0))
     m.ambient = 1
     m.diffuse = 0
     m.specular = 0
     eyev = Vector(0, 0, -1)
     normalv = Vector(0, 0, -1)
     light = PointLight(Point(0, 0, -10), Color(1, 1, 1))
     c1 = PointLight.lighting(m, Sphere(), light, Point(0.9, 0, 0), eyev, normalv, False)
     c2 = PointLight.lighting(m, Sphere(), light, Point(1.1, 0, 0), eyev, normalv, False)
     self.assertEqual(c1, Color(1, 1, 1))
     self.assertEqual(c2, Color(0, 0, 0))
 def test_light_eye_reflection(self):
     m = Material()
     position = Point(0, 0, 0)
     eyev = Vector(0, -math.sqrt(2) / 2, -math.sqrt(2) / 2)
     normalv = Vector(0, 0, -1)
     light = PointLight(Point(0, 10, -10), Color(1, 1, 1))
     result = PointLight.lighting(m, Sphere(), light, position, eyev, normalv, False)
     self.assertEqual(result, Color(1.6364, 1.6364, 1.6364))
 def test_light_behind_surface(self):
     m = Material()
     position = Point(0, 0, 0)
     eyev = Vector(0, 0, -1)
     normalv = Vector(0, 0, -1)
     light = PointLight(Point(0, 0, 10), Color(1, 1, 1))
     result = PointLight.lighting(m, Sphere(), light, position, eyev, normalv, False)
     self.assertEqual(result, Color(0.1, 0.1, 0.1))
 def test_lighting_surface_in_shadow(self):
     m = Material()
     position = Point(0, 0, 0)
     eyev = Vector(0, 0, -1)
     normalv = Vector(0, 0, -1)
     light = PointLight(Point(0, 0, -10), Color(1, 1, 1))
     in_shadow = True
     result = PointLight.lighting(m, Sphere(), light, position, eyev, normalv, in_shadow)
     self.assertEqual(result, Color(0.1, 0.1, 0.1))
Beispiel #5
0
        for x in range(canvas_pixels):
            world_x = -half + pixel_size * x

            position = Point(world_x, world_y, wall_z)

            r = Ray(ray_origin, Vector.normalize(position - ray_origin))
            # shrink along y-axis
            # r = r.transform(Transformations.scaling(1, 0.5, 1))

            # shrink along x-axis
            # r = r.transform(Transformations.scaling(0.5, 1, 1))

            # shrink and rotate
            # r = r.transform(Transformations.rotation_z(math.pi / 4)).transform(Transformations.scaling(0.5, 1, 1))

            # shrink and skew
            # r = r.transform(Transformations.shearing(1, 0, 0, 0, 0, 0)).transform(Transformations.scaling(0.5, 1, 1))

            xs = shape.intersect(r)

            hit = Intersection.hit(xs)
            if hit is not None:
                point = Ray.position(r, hit.t)
                normal = shape.normal_at(point)
                eye = -r.direction
                color = PointLight.lighting(hit.object.material, hit.object,
                                            light, point, eye, normal, False)
                canvas.write_pixel(x, y, color)

    canvas.canvas_to_ppm()