Exemplo n.º 1
0
def default_world():
    light = point_light(Point(-10, 10, -10), Color(1, 1, 1))
    s1 = Sphere()
    s1.material.color = Color(.8, 1.0, .6)
    s1.material.diffuse = .7
    s1.material.specular = .2

    s2 = set_transform(Sphere(), Scaling(.5, .5, .5))

    return World(objects=[s1, s2], light=light)
Exemplo n.º 2
0
def make_middle():
    middle = set_transform(Sphere(), Translation(-0.5, 1, 0.5))
    middle.material = Material()
    middle.material.color = Color(0.1, 1, 0.5)
    middle.material.diffuse = 0.7
    middle.material.specular = 0.3
    return middle
Exemplo n.º 3
0
def make_right():
    right = set_transform(Sphere(),
                          Translation(1.5, 0.5, -0.5) * Scaling(0.5, 0.5, 0.5))
    right.material = Material()
    right.material.color = Color(0.5, 1, 0.1)
    right.material.diffuse = 0.7
    right.material.specular = 0.3
    return right
Exemplo n.º 4
0
def make_left():
    left = set_transform(
        Sphere(),
        Translation(-1.5, 0.33, -0.75) * Scaling(0.33, 0.33, 0.33))
    left.material = Material()
    left.material.color = Color(1, 0.8, 0.1)
    left.material.diffuse = 0.7
    left.material.specular = 0.3
    return left
Exemplo n.º 5
0
def make_middle():
    middle = set_transform(Sphere(), Translation(-0.5, 1, 0.5))
    middle.material = Material()
    middle.material.color = Color(0.1, 1, 0.5)
    middle.material.diffuse = 0.7
    middle.material.specular = 0.3
    middle.material.pattern = gradient_pattern(BLUE, GREEN)
    middle.material.pattern.transform = Scaling(.2, .2, .2)
    return middle
Exemplo n.º 6
0
def make_left():
    left = set_transform(
        Sphere(),
        Translation(-1.5, 0.33, -0.75) * Scaling(0.33, 0.33, 0.33))
    left.material = Material()
    left.material.color = Color(1, 0.8, 0.1)
    left.material.diffuse = 0.7
    left.material.specular = 0.3
    left.material.pattern = checkers_pattern(WHITE, BLACK)
    return left
Exemplo n.º 7
0
def make_right():
    right = set_transform(Sphere(),
                          Translation(1.5, 0.5, -0.5) * Scaling(0.5, 0.5, 0.5))
    right.material = Material()
    #right.material.color = Color(0.5, 1, 0.1)
    #right.material.diffuse = 0.7
    #right.material.specular = 0.3
    right.material.pattern = ring_pattern(GREEN, BLACK)
    right.material.pattern.transform = Scaling(.2, .2, .2) * rotation_x(
        math.pi / 2)
    return right
Exemplo n.º 8
0
from ray_tracer.colors import RED
from ray_tracer.intersections import intersect, hit
from ray_tracer.rays import Ray
from ray_tracer.shapes import Sphere
from ray_tracer.tuples import Point, normalize

ray_origin = Point(0, 0, -5)

wall_z = 10
wall_size = 7
canvas_pixels = 100
pixel_size = wall_size / canvas_pixels
half = wall_size / 2

canvas = Canvas(canvas_pixels, canvas_pixels)
shape = Sphere()

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

        position = Point(world_x, world_y, wall_z)
        r = Ray(ray_origin, normalize(position - ray_origin))
        xs = intersect(shape, r)
        if hit(xs) is not None:
            write_pixel(canvas, x, y, RED)

path = Path(__file__).parent / "chap5.png"
canvas_to_png(str(path), canvas)
Exemplo n.º 9
0
def step_impl(context, s):
    _s = Sphere()
    setattr(context, s, _s)
Exemplo n.º 10
0
def glass_sphere():
    s = Sphere()
    s.material.transparency = 1.0
    s.material.refractive_index = 1.5
    return s
Exemplo n.º 11
0
def make_wall(theta):
    transform = Translation(0, 0, 5) * rotation_y(theta) * rotation_x(
        math.pi / 2) * Scaling(10, .01, 10)
    wall = set_transform(Sphere(), transform)
    wall.material = floor_material()
    return wall
Exemplo n.º 12
0
def make_floor():
    output = set_transform(Sphere(), Scaling(10, .01, 10))
    output.material = floor_material()
    return output
Exemplo n.º 13
0
from pathlib import Path

from ray_tracer.canvas import Canvas, write_pixel, canvas_to_png
from ray_tracer.colors import Color, WHITE
from ray_tracer.intersections import intersect, hit
from ray_tracer.lights import point_light
from ray_tracer.material import Material, lighting
from ray_tracer.rays import Ray, position
from ray_tracer.shapes import Sphere
from ray_tracer.tuples import Point, normalize

ray_origin = Point(0, 0, -5)
wall_z = 10
wall_size = 7
light = point_light(Point(-10, 10, -10), WHITE)
shape = Sphere()
shape.material = Material()
shape.material.color = Color(1, .2, 1)


def get_color(a_hit, ray):
    point = position(ray, a_hit.t)
    normal = a_hit.object.normal_at(point)
    eye = -ray.direction
    color = lighting(a_hit.object.material, a_hit.object, light, point, eye,
                     normal)
    return color


def cast_this_point(canvas, canvas_x, canvas_y, world_x, world_y):
    spot_on_wall = Point(world_x, world_y, wall_z)
Exemplo n.º 14
0
def step_impl(context, s):
    _s = Sphere()
    set_props_from_table(context, _s)
    setattr(context, s, _s)