예제 #1
0
 def default(cls):
     world = cls()
     world.light = PointLight(Point(-10, 10, -10), Color(1, 1, 1))
     m = Material()
     m.color = Color(0.8, 1.0, 0.6)
     m.diffuse = 0.7
     m.specular = 0.2
     s1 = Sphere()
     s1.set_material(m)
     s2 = Sphere()
     s2.set_transform(Scaling(0.5, 0.5, 0.5))
     world.objects.extend([s1, s2])
     return world
예제 #2
0
 def test_lighting_with_pattern_applied(self):
     m = Material()
     m.pattern = StripePattern(Color.white(), Color.black())
     m.ambient = 1
     m.diffuse = 0
     m.specular = 0
     eyev = Vector(0, 0, -1)
     normalv = Vector(0, 0, -1)
     light = PointLight(Point(0, 0, -10), Color.white())
     c1 = m.lighting(Sphere(), light, Point(0.9, 0, 0), eyev, normalv, False)
     c2 = m.lighting(Sphere(), light, Point(1.1, 0, 0), eyev, normalv, False)
     assert c1 == Color.white()
     assert c2 == Color.black()
예제 #3
0
def test_lighting_pattern():
    s = Sphere()
    m = Material()
    m.pattern = StripePattern(Color(1, 1, 1), Color(0, 0, 0))
    m.ambient = 1
    m.diffuse = 0
    m.specular = 0
    eyev = Vector(0, 0, -1)
    normalv = Vector(0, 0, -1)
    light = PointLight(Point(0, 0, -10), Color(1, 1, 1))
    c1 = m.lighting(s, light, Point(0.9, 0, 0), eyev, normalv, False)
    c2 = m.lighting(s, light, Point(1.1, 0, 0), eyev, normalv, False)
    assert c1 == Color(1, 1, 1)
    assert c2 == Color(0, 0, 0)
예제 #4
0
def test_default_world():
    light = PointLight(Point(-10, 10, -10), Color(1, 1, 1))
    s1 = Sphere()
    m = Material()
    m.color = Color(0.8, 1.0, 0.6)
    m.diffuse = 0.7
    m.specular = 0.2
    s1.set_material(m)
    s2 = Sphere()
    t = Scaling(0.5, 0.5, 0.5)
    s2.set_transform(t)
    w = World.default()
    assert w.light == light
    assert s1 in w.objects
    assert s2 in w.objects
예제 #5
0
# intensity: [ 0.2, 0.2, 0.2 ]
# # ======================================================
# # define some constants to avoid duplication
# # ======================================================
# - define: white-material
# value:
# color: [ 1, 1, 1 ]
# diffuse: 0.7
# ambient: 0.1
# specular: 0.0
# reflective: 0.1
white = Material()
white.color = Color(1, 1, 1)
white.diffuse = 0.7
white.ambient = 0.1
white.specular = 0.0
white.reflective = 0.1

# - define: blue-material
# extend: white-material
# value:
# color: [ 0.537, 0.831, 0.914 ]
blue = copy.deepcopy(white)
blue.color = Color(0.537, 0.831, 0.914)

# - define: red-material
# extend: white-material
# value:
# color: [ 0.941, 0.322, 0.388 ]
red = copy.deepcopy(white)
red.color = Color(0.941, 0.322, 0.388)