Beispiel #1
0
def test_both_transform():
    s = Sphere()
    s.set_transform(Scaling(2, 2, 2))
    pattern = _TestPattern()
    pattern.set_pattern_transform(Translation(0.5, 1, 1.5))
    c = pattern.pattern_at_shape(s, Point(2.5, 3, 3.5))
    assert c == Color(0.75, 0.5, 0.25)
Beispiel #2
0
def test_refracted_color():
    w = World().default()
    a = w.objects[0]
    a.material.ambient = 1.0
    a.material.pattern = _TestPattern()
    b = w.objects[1]
    b.material.transparency = 1.0
    b.material.refractive_index = 1.5
    r = Ray(Point(0, 0, 0.1), Vector(0, 1, 0))
    xs = Intersections(
        Intersection(-0.9899, a),
        Intersection(-0.4899, b),
        Intersection(0.4899, b),
        Intersection(0.9899, a),
    )
    comps = xs[2].prepare_computation(r, xs)
    c = w.refracted_color(comps, 5)
    print(c)
    assert c == Color(0, 0.99888, 0.04725)
Beispiel #3
0
def test_pattern_transform():
    s = Sphere()
    p = _TestPattern()
    p.set_pattern_transform(Scaling(2, 2, 2))
    c = p.pattern_at_shape(s, Point(2, 3, 4))
    assert c == Color(1, 1.5, 2)
Beispiel #4
0
def test_object_transform():
    s = Sphere()
    s.set_transform(Scaling(2, 2, 2))
    pattern = _TestPattern()
    c = pattern.pattern_at_shape(s, Point(2, 3, 4))
    assert c == Color(1, 1.5, 2)
Beispiel #5
0
def test_assign_transform():
    pattern = _TestPattern()
    pattern.set_pattern_transform(Translation(1, 2, 3))
    assert pattern.transform == Translation(1, 2, 3)
Beispiel #6
0
def test_default_transform():
    pattern = _TestPattern()
    assert pattern.transform == Identity()