def test_unitvector(self): v1 = Vec3(1, 2, 3) v2 = Vec3.unitVector(v1) self.assertEqual(v2.Length, 1) self.assertEqual(v2.SquaredLength, 1) self.assertEqual(v2[0], 0.2672612419124244) self.assertEqual(v2[1], 0.5345224838248488) self.assertEqual(v2[2], 0.8017837257372732) self.assertEqual(v1[0], 1) self.assertEqual(v1[1], 2) self.assertEqual(v1[2], 3)
def color(r, world, depth): bHit, rec = world.hit(r, 0.001, sys.float_info.max) if bHit: if depth < 50: bScattered, attenuation, scattered = rec.Material.scatter(r, rec) if bScattered: return attenuation * color(scattered, world, depth + 1) else: return Vec3(0, 0, 0) else: return Vec3(0, 0, 0) else: unitDirection = Vec3.unitVector(r.Direction) t = 0.5 * (unitDirection.Y + 1.0) return (1.0 - t) * Vec3(1, 1, 1) + t * Vec3(0.5, 0.7, 1.0)