示例#1
0
    def test_color_at_with_mutually_reflective_surfaces(self):
        w = World()
        w.light_source = PointLight(Point(0, 0, 0), Color.white())
        lower = Plane()
        lower.material.reflective = 1
        lower.transformation = translation(0, -1, 0)
        upper = Plane()
        upper.material.reflective = 1
        upper.transformation = translation(0, 1, 0)
        w.add(lower, upper)
        r = Ray(Point(0, 0, 0), Vector(0, 1, 0))

        # Avoid Infinite Recursion
        w.color_at(r)
        assert True
示例#2
0
 def test_reflected_color_at_max_recursive_depth(self, default_world):
     w = default_world
     shape = Plane()
     shape.material.reflective = 0.5
     shape.transformation = translation(0, -1, 0)
     w.add(shape)
     r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2) / 2, sqrt(2) / 2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     color = w.reflected_color(comps, 0)
     assert color == Color.black()
示例#3
0
 def test_shade_hit_with_reflective_material(self, default_world):
     w = default_world
     shape = Plane()
     shape.material.reflective = 0.5
     shape.transformation = translation(0, -1, 0)
     w.add(shape)
     r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2) / 2, sqrt(2) / 2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     color = w.shade_hit(comps)
     assert color == Color(0.87676, 0.92434, 0.82917)
示例#4
0
 def test_reflected_color_for_reflective_material(self, default_world):
     w = default_world
     shape = Plane()
     shape.material.reflective = 0.5
     shape.transformation = translation(0, -1, 0)
     w.add(shape)
     r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2) / 2, sqrt(2) / 2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     color = w.reflected_color(comps)
     assert color == Color(0.19033, 0.23791, 0.14274)
示例#5
0
 def test_shade_hit_with_transparent_material(self, default_world):
     w = default_world
     floor = Plane()
     floor.transformation = translation(0, -1, 0)
     floor.material.transparency = 0.5
     floor.material.refractive_index = 1.5
     ball = Sphere()
     ball.material.color = Color(1, 0, 0)
     ball.material.ambient = 0.5
     ball.transformation = translation(0, -3.5, -0.5)
     w.add(floor, ball)
     r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2) / 2, sqrt(2) / 2))
     xs = Intersections(Intersection(sqrt(2), floor))
     comps = xs[0].prepare_computations(r, xs)
     color = w.shade_hit(comps, 5)
     assert color == Color(0.93642, 0.68642, 0.68642)
示例#6
0
    floor.material.refractive_index = 1.333

    under = Sphere()
    under.transformation = translation(0, -.5, 0) * scaling(.25, .25, .25)
    under.material.color = Color(0, .8, 0)
    under.material.refractive_index = 1.5
    under.material.ambient = .8

    above = Sphere()
    above.transformation = translation(1, .5, 0) * scaling(.5, .5, .5)
    above.material.color = Color(.2, 0, 0)
    above.material.diffuse = .8
    above.material.ambient = .5

    bottom = Plane()
    bottom.transformation = translation(0, -1.25, 0)
    bottom.material.pattern = StripePattern(Color.black(), Color(0, .2, .2))
    bottom.material.diffuse = .25
    bottom.material.ambient = .25

    world = World()
    world.add(floor, under, above, bottom)
    world.light_source = PointLight(Point(-10, 10, -10), Color.white())

    camera = Camera(300, 200, pi / 3)
    camera.transformation = view_transform(Point(0, 1.5, -5), Point(0, 1, 0), Vector(0, 1, 0))

    canvas = camera.render(world)

    write_ppm_to_file(canvas.to_ppm(), f'..{sep}..{sep}resources{sep}reflect_refract.ppm')