Ejemplo n.º 1
0
    def test_computing_normal_on_scaled_sphere(self):
        s = Sphere()
        s.set_transform(scaling(1, 0.5, 1))

        n = s.normal_at(point(0, math.sqrt(2) / 2, -math.sqrt(2) / 2))

        self.assert_tuple_equals(vector(0, 0.97014, -0.24254), n, 0.001)
Ejemplo n.º 2
0
    def test_computing_normal_on_translated_sphere(self):
        s = Sphere()
        s.set_transform(translation(0, 1, 0))

        n = s.normal_at(point(0, 1.70711, -0.70711))

        self.assert_tuple_equals(vector(0, 0.70711, -0.70711), n, 0.001)
Ejemplo n.º 3
0
    def test_normal_is_normalized_vector(self):
        s = Sphere()

        n = s.normal_at(
            point(math.sqrt(3) / 3,
                  math.sqrt(3) / 3,
                  math.sqrt(3) / 3))

        self.assertEqual(n.normalize(), n)
Ejemplo n.º 4
0
    def test_normal_on_sphere_at_point_on_none_axial_point(self):
        s = Sphere()

        n = s.normal_at(
            point(math.sqrt(3) / 3,
                  math.sqrt(3) / 3,
                  math.sqrt(3) / 3))

        self.assertEqual(n.normalize(), n)
Ejemplo n.º 5
0
wall_size = 7.0
canvas_pixels = 1000
pixel_size = wall_size / canvas_pixels
half = wall_size / 2

c = Canvas(canvas_pixels, canvas_pixels)
col = color(1, 0, 0)

start_time = time.time()
for y in range(canvas_pixels):
    elapsed_time = time.time() - start_time
    if elapsed_time > 0 and y > 0:
        print("time_to_finish: " + str(1.0 * (canvas_pixels - y) /
                                       (1.0 * y / elapsed_time)))
    world_y = half - pixel_size * y
    for x in range(canvas_pixels):
        world_x = -half + pixel_size * x
        position = point(world_x, world_y, wall_z)
        ray = Ray(ray_origin, (position - ray_origin).normalize())
        xs = s.intersect(ray)
        if hit(xs):
            hit_point = ray.position(hit(xs).t)
            norma_at_hit_point = s.normal_at(hit_point)
            eye = -ray.direction
            color = s.material.lighting(light, hit_point, eye,
                                        norma_at_hit_point)

            c.write_pixel(x, y, color)

c.save_to_file('sphere6.ppm')
Ejemplo n.º 6
0
    def test_normal_on_sphere_at_point_on_y_axis(self):
        s = Sphere()

        n = s.normal_at(point(0, 1, 0))

        self.assertEqual(vector(0, 1, 0), n)