예제 #1
0
def test_assigning_a_material():
    # Given
    s = MockShape()
    m = Material()
    m.ambient = 1
    # When
    s.material = m
    # Then
    assert s.material == m
예제 #2
0
def test_lighting_with_the_eye_in_the_path_of_the_reflection_vector():
    # Given
    m = Material()
    position = Point(0, 0, 0)
    eyev = Vector(0, -sqrt(2) / 2, -sqrt(2) / 2)
    normalv = Vector(0, 0, -1)
    light = PointLight(Point(0, 10, -10), Color(1, 1, 1))
    object = Sphere()
    # When
    result = m.lighting(object, light, position, eyev, normalv)
    # Then
    assert result == Color(1.6364, 1.6364, 1.6364)
예제 #3
0
def test_lighting_with_the_light_behind_the_surface():
    # Given
    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))
    object = Sphere()
    # When
    result = m.lighting(object, light, position, eyev, normalv)
    # Then
    assert result == Color(0.1, 0.1, 0.1)
예제 #4
0
def test_lighting_with_the_eye_between_light_and_surface_eye_offset_45degree():
    # Given
    m = Material()
    position = Point(0, 0, 0)
    eyev = Vector(0, sqrt(2) / 2, sqrt(2) / 2)
    normalv = Vector(0, 0, -1)
    light = PointLight(Point(0, 0, -10), Color(1, 1, 1))
    object = Sphere()
    # When
    result = m.lighting(object, light, position, eyev, normalv)
    # Then
    assert result == Color(1.0, 1.0, 1.0)
예제 #5
0
def test_lighting_with_the_eye_opposite_surface_light_offset_45degree():
    # Given
    m = Material()
    position = Point(0, 0, 0)
    eyev = Vector(0, 0, -1)
    normalv = Vector(0, 0, -1)
    light = PointLight(Point(0, 10, -10), Color(1, 1, 1))
    object = Sphere()
    # When
    result = m.lighting(object, light, position, eyev, normalv)
    # Then
    assert result == Color(0.7364, 0.7364, 0.7364)
예제 #6
0
def test_the_default_material():
    # Given
    s = MockShape()
    # When
    m = s.material
    # Then
    assert m == Material()
예제 #7
0
def test_the_default_material():
    # Given
    m = Material()
    # Then
    assert m.color == Color(1, 1, 1)
    assert m.ambient == 0.1
    assert m.diffuse == 0.9
    assert m.specular == 0.9
    assert m.shininess == 200.0
예제 #8
0
def test_lighting_with_a_pattern_applied():
    # Given
    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))
    object = Sphere()
    # When
    c1 = m.lighting(object, light, Point(0.9, 0, 0), eyev, normalv)
    c2 = m.lighting(object, light, Point(1.1, 0, 0), eyev, normalv)
    # Then
    assert c1 == Color(1, 1, 1)
    assert c2 == Color(0, 0, 0)
예제 #9
0
from raytracerchallenge_python.plane import Plane
from raytracerchallenge_python.cube import Cube
# from raytracerchallenge_python.stripe_pattern import StripePattern
# from raytracerchallenge_python.checkers_pattern import CheckersPattern
# from raytracerchallenge_python.ring_pattern import RingPattern


if __name__ == "__main__":
    # pattern = StripePattern(Color(1, 0, 0), Color(1, 1, 1))
    # pattern = CheckersPattern(Color(1, 0, 0), Color(1, 1, 1))
    pattern = GradientPattern(Color(1, 0, 0), Color(1, 1, 1))
    # pattern = RingPattern(Color(1, 0, 0), Color(1, 1, 1))
    pattern.transform = scaling(0.2, 0.2, 0.2)

    floor = Plane()
    floor.material = Material()
    floor.material.color = Color(1, 0.9, 0.9)
    # floor.material.pattern = pattern

    backdrop = Plane()
    backdrop.transform = \
        rotation_y(pi / 3) * translation(0, 0, 5) * rotation_x(pi / 2)

    backdrop2 = Plane()
    backdrop2.transform = \
        rotation_y(-pi / 3) * translation(0, 0, 5) * rotation_x(pi / 2)

    middle = Sphere()
    # middle = glass_sphere()
    middle.transform = translation(-0.5, 1, 0.5)
    # middle.reflective = 1.0
예제 #10
0
 def __init__(self):
     self.transform = identity_matrix()
     self.material = Material()
     self.parent = None
예제 #11
0
from raytracerchallenge_python.intersection import Intersections
from raytracerchallenge_python.canvas import Canvas
from raytracerchallenge_python.material import Material
from raytracerchallenge_python.point_light import PointLight

if __name__ == "__main__":
    ray_origin = Point(0, 0, -5)
    wall_z = 10
    wall_size = 7.0
    canvas_pixcels = 100
    pixel_size = wall_size / canvas_pixcels
    half = wall_size / 2

    canvas = Canvas(canvas_pixcels, canvas_pixcels)
    shape = Sphere()
    shape.material = Material()
    shape.material.color = Color(1, 0.2, 1)

    light_position = Point(-10, 10, -10)
    light_color = Color(1, 1, 1)
    light = PointLight(light_position, light_color)

    # for each row of pixels in the canvas
    for y in range(canvas_pixcels):
        # compute the world y coordinate (top = +half, bottom = -half)
        world_y = half - pixel_size * y

        for x in range(canvas_pixcels):
            # compute the world x coordinate (left = -half, right = half)
            world_x = -half + pixel_size * x
예제 #12
0
def test_material_equality_with_different_materials():
    m1 = Material()
    m2 = Material()
    m2.ambient = 1
    assert m1 != m2
예제 #13
0
def test_material_equality_with_identical_materials():
    m1 = Material()
    m2 = Material()
    assert m1 == m2
예제 #14
0
def test_transparency_and_refractive_index_for_the_default_material():
    # Given
    m = Material()
    # Then
    assert m.transparency == 0.0
    assert m.refractive_index == 1.0
예제 #15
0
def test_reflectivity_for_the_default_material():
    # Given
    m = Material()
    # Then
    assert m.reflective == 0.0