Ejemplo n.º 1
0
 def test_hit_all_intersections_negative_t(self):
     s = Sphere()
     i1 = Intersection(-2, s)
     i2 = Intersection(-1, s)
     xs = Intersection.intersections(i2, i1)
     i = Intersection.hit(xs)
     self.assertIsNone(i)
Ejemplo n.º 2
0
 def test_hit_all_intersections_positive_t(self):
     s = Sphere()
     i1 = Intersection(1, s)
     i2 = Intersection(2, s)
     xs = Intersection.intersections(i2, i1)
     i = Intersection.hit(xs)
     self.assertEqual(i, i1)
Ejemplo n.º 3
0
 def test_hit_some_intersections_negative_t(self):
     s = Sphere()
     i1 = Intersection(-1, s)
     i2 = Intersection(1, s)
     xs = Intersection.intersections(i2, i1)
     i = Intersection.hit(xs)
     self.assertEqual(i, i2)
Ejemplo n.º 4
0
 def test_hit_lowest_nonnegative_intersection(self):
     s = Sphere()
     i1 = Intersection(5, s)
     i2 = Intersection(7, s)
     i3 = Intersection(-3, s)
     i4 = Intersection(2, s)
     xs = Intersection.intersections(i1, i2, i3, i4)
     i = Intersection.hit(xs)
     self.assertEqual(i, i4)
Ejemplo n.º 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()