def test_light_directly_behind_surface_and_eye(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 = lighting(m, light, position, eyev, normalv) self.assertEqual(result, Color(0.1, 0.1, 0.1))
def test_light_and_eye_perpendicular(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 = lighting(m, light, position, eyev, normalv) self.assertEqual(result, Color(1.9, 1.9, 1.9))
def test_light_perpendicular_and_eye_at_45(self): r = math.sqrt(2) / 2 m = Material() position = Point(0, 0, 0) eyev = Vector(0, r, -r) normalv = Vector(0, 0, -1) light = PointLight(Point(0, 0, -10), Color(1, 1, 1)) result = lighting(m, light, position, eyev, normalv) self.assertEqual(result, Color(1.0, 1.0, 1.0))
def test_light_at_45_and_eye_at_neg_45(self): r = math.sqrt(2) / 2 m = Material() position = Point(0, 0, 0) eyev = Vector(0, -r, -r) normalv = Vector(0, 0, -1) light = PointLight(Point(0, 10, -10), Color(1, 1, 1)) result = lighting(m, light, position, eyev, normalv) x = 1.6363961 self.assertColorEqual(result, Color(x, x, x))
for y in range(H): p = m * Point(x, y, 0) ray = Ray(eye, (p - eye).norm()) xs = sphere.intersect(ray) if xs: dprint(f"\nSphere hit at {x}, {y}...") dprint("p: {}".format(p)) dprint("ray: {}".format(ray)) dprint("xs: {}".format(str(xs))) hit = intersection.hit(xs) dprint("hit: {}".format(hit)) point = ray.position(hit.t) dprint("point: {}".format(point)) normal = hit.object.normal(point) dprint("normal: {}".format(normal)) eyev = -ray.direction dprint("eyev: {}".format(eyev)) c = lighting(hit.object.material, light, point, eyev, normal, components=True) dprint("color: {}".format(c)) color = c[0] + c[1] + c[2] pix[x, y] = color.rgb() pause() print(x) im.show()