def test_initialize_stripe(self): """Test that we can initialize a stripe pattern""" stripes = patterns.StripePattern(WHITE, BLACK) self.assertEqual(stripes.color_a, WHITE) self.assertEqual(stripes.color_b, BLACK) self.assertEqual(stripes.transform, transforms.Identity(4))
def test_pattern(self): """Test that the pattern of a material can change its color""" m = materials.Material(pattern=patterns.StripePattern( colors.Color( 0, 0, 0, ), colors.Color(1, 1, 1)), ambient=1, diffuse=0, specular=0) eyev = vectors.Vector(0, 0, -1) normalv = vectors.Vector(0, 0, -1) light = lights.PointLight(points.Point(0, 0, -10), colors.Color(1, 1, 1)) color_1 = m.lighting(light, points.Point(0.9, 0, 0), eyev, normalv, in_shadow=False) color_2 = m.lighting(light, points.Point(1.1, 0, 0), eyev, normalv, in_shadow=False) self.assertEqual(color_1, colors.Color(0, 0, 0)) self.assertEqual(color_2, colors.Color(1, 1, 1))
def test_stripes_in_z(self): """Test that the default pattern is constant in z""" stripes = patterns.StripePattern(WHITE, BLACK) self.assertEqual(stripes.pattern_at(points.Point(0, 0, 0)), WHITE) self.assertEqual(stripes.pattern_at(points.Point(0, 0, 1)), WHITE) self.assertEqual(stripes.pattern_at(points.Point(0, 0, 2)), WHITE)
def test_pattern_transformation(self): """Test that pattern is affected by a pattern transform""" shape = shapes.Sphere() p = patterns.StripePattern(WHITE, BLACK) p.set_transform(transforms.Scale(2, 2, 2)) self.assertEqual(p.pattern_at_shape(shape, points.Point(1.5, 0, 0)), WHITE)
def test_pattern_object_transformation(self): """Test that pattern is affected by pattern and object transforms""" shape = shapes.Sphere() shape.set_transform(transforms.Scale(2, 2, 2)) p = patterns.StripePattern(WHITE, BLACK) p.set_transform(transforms.Translate(0.5, 0, 0)) self.assertEqual(p.pattern_at_shape(shape, points.Point(2.5, 0, 0)), WHITE)
def test_stripes_in_x(self): """Test that the default pattern alternates in x""" stripes = patterns.StripePattern(WHITE, BLACK) self.assertEqual(stripes.pattern_at(points.Point(0, 0, 0)), WHITE) self.assertEqual(stripes.pattern_at(points.Point(0.9, 0, 0)), WHITE) self.assertEqual(stripes.pattern_at(points.Point(1, 0, 0)), BLACK) self.assertEqual(stripes.pattern_at(points.Point(-0.1, 0, 0)), BLACK) self.assertEqual(stripes.pattern_at(points.Point(-1, 0, 0)), BLACK) self.assertEqual(stripes.pattern_at(points.Point(-1.1, 0, 0)), WHITE)