Esempio n. 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
Esempio n. 2
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
Esempio n. 3
0
from raytracer.shapes import Sphere
from raytracer.tuples import Point, Color

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

    canvas = Canvas(canvas_pixels, canvas_pixels)
    red = Color(1, 0, 0)
    sphere = Sphere()
    m = Material()
    m.color = Color(1, 0.2, 1)
    sphere.material = m

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

    for y in range(canvas_pixels):
        world_y = half - pixel_size * y
        for x in range(canvas_pixels):
            world_x = -half + pixel_size * x

            position = Point(world_x, world_y, wall_z)
            ray = Ray(ray_origin, (position - ray_origin).normalize())
            hit = sphere.intersect(ray).hit()
            if hit:
                point = ray.position(hit.t)
                normal = hit.object.normal_at(point)
Esempio n. 4
0
# - add: light
# at: [ -400, 50, -10 ]
# 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: