def test_maximum_recursion_depth_color_at(): w = World().default() s = Plane() s.material.reflective = 0.5 s.set_transform(Translation(0, -1, 0)) w.objects.append(s) r = Ray(Point(0, 0, -3), Vector(0, -math.sqrt(2) / 2, math.sqrt(2) / 2)) i = Intersection(math.sqrt(2), s) comps = i.prepare_computation(r) color = w.reflected_color(comps, 0) assert color == Color(0, 0, 0)
def test_shade_hit_reflective(): w = World().default() s = Plane() s.material.reflective = 0.5 s.set_transform(Translation(0, -1, 0)) w.objects.append(s) r = Ray(Point(0, 0, -3), Vector(0, -math.sqrt(2) / 2, math.sqrt(2) / 2)) i = Intersection(math.sqrt(2), s) comps = i.prepare_computation(r) c = w.shade_hit(comps) assert c == Color(0.87677, 0.92436, 0.82918)
def test_reflected_color(): w = World().default() s = Plane() s.material.reflective = 0.5 s.set_transform(Translation(0, -1, 0)) w.objects.append(s) r = Ray(Point(0, 0, -3), Vector(0, -math.sqrt(2) / 2, math.sqrt(2) / 2)) i = Intersection(math.sqrt(2), s) comps = i.prepare_computation(r) c = w.reflected_color(comps) print(c) assert c == Color(0.19032, 0.2379, 0.14274)
def test_mutually_reflective_color_at(): w = World() w.light = PointLight(Point(0, 0, 0), Color(1, 1, 1)) lower = Plane() lower.material.reflective = 1 lower.set_transform(Translation(0, -1, 0)) w.objects.append(lower) upper = Plane() upper.material.reflective = 1 upper.set_transform(Translation(0, 1, 0)) w.objects.append(upper) r = Ray(Point(0, 0, 0), Vector(0, 1, 0)) assert w.color_at(r) is not None
def shade_hit_transparent(): w = World().default() floor = Plane() floor.set_transform(Translation(0, -1, 0)) floor.material.transparency = 0.5 floor.material.refractive_index = 1.5 w.objects.append(floor) ball = Sphere() ball.material.color = Color(1, 0, 0) ball.material.ambient = 0.5 ball.set_transform(Translation(0, -3.5, -0.5)) w.objects.append(ball) r = Ray(Point(0, 0, -3), Vector(0, -math.sqrt(2) / 2, math.sqrt(2) / 2)) xs = Intersections(Intersection(math.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)
# - add: plane # material: # color: [ 1, 1, 1 ] # ambient: 1 # diffuse: 0 # specular: 0 # transform: # - [ rotate-x, 1.5707963267948966 ] # pi/2 # - [ translate, 0, 0, 500 ] p = Plane() p.material.color = Color(1, 1, 1) p.material.ambient = 1 p.material.diffuse = 0 p.material.specular = 0 p.set_transform(Translation(0, 0, 500) * RotationX(math.pi / 2)) w.objects.append(p) # # ====================================================== # # describe the elements of the scene # # ====================================================== # - add: sphere # material: # color: [ 0.373, 0.404, 0.550 ] # diffuse: 0.2 # ambient: 0.0 # specular: 1.0 # shininess: 200 # reflective: 0.7 # transparency: 0.7 # refractive-index: 1.5