Ejemplo n.º 1
0
def make_single_frame(objects, view_transform_, camera_resolution):
    lights = [
        point_light(Point(10, 10, 15), WHITE),
        point_light(Point(-10, -10, 15), WHITE)
    ]
    world = World(objects=objects, light=lights)
    camera = Camera(*camera_resolution, math.pi / 3)
    camera.transform = view_transform_
    canvas = camera.render(world)
    return canvas
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def draw_objects(objects):
    logging.basicConfig(
        level=logging.INFO,
        format=
        '%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(name)s %(message)s'
    )

    lights = [
        point_light(Point(10, 10, 15), WHITE),
        point_light(Point(-10, -10, 15), WHITE)
    ]
    world = World(objects=objects, light=lights)

    camera = Camera(100, 50, math.pi / 3)
    camera.transform = view_transform(Point(12, -6, 10), Point(0, 0, 0),
                                      Vector(0, 0, 1))
    canvas = camera.render(world)

    path = Path(__file__).parent / "output.png"
    canvas_to_png(str(path), canvas)
Ejemplo n.º 4
0
def main(camera_resolution):
    logging.basicConfig(
        level=logging.INFO,
        format=
        '%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(name)s %(message)s'
    )

    objects = (make_floor(), make_middle(), make_right(), make_left())

    light = point_light(Point(-10, 10, -10), Color(1, 1, 1))
    world = World(objects=objects, light=light)

    camera = Camera(*camera_resolution, math.pi / 3)
    camera.transform = view_transform(Point(0, 1 / 5, -5), Point(0, 1, 0),
                                      Vector(0, 1, 0))
    canvas = camera.render(world)

    path = Path(__file__).parent / "chap10.png"
    canvas_to_png(str(path), canvas)
Ejemplo n.º 5
0
def main(canvas_dimensions):
    logging.basicConfig(
        level=logging.INFO,
        format=
        '%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(process)d %(name)s %(message)s'
    )

    objects = (make_floor(), make_wall(-math.pi / 4), make_wall(math.pi / 4),
               make_middle(), make_right(), make_left())

    light = point_light(Point(-10, 10, -10), Color(1, 1, 1))
    world = World(objects=objects, light=light)
    camera = Camera(canvas_dimensions[0], canvas_dimensions[1], math.pi / 3)
    camera.transform = view_transform(Point(0, 1 / 5, -5), Point(0, 1, 0),
                                      Vector(0, 1, 0))

    start = time.time()
    canvas = camera.render(world)
    stop = time.time()

    logging.info("Rendering took %s seconds", stop - start)

    path = Path(__file__).parent / "chap7.png"
    canvas_to_png(str(path), canvas)
Ejemplo n.º 6
0
def step_impl(context, world, x, y, z, red, green, blue):
    _world = getattr(context, world)
    _world.light = point_light(Point(x, y, z), Color(red, green, blue))
Ejemplo n.º 7
0
def step_impl(context, light, position, intensity):
    _position = getattr(context, position)
    _intensity = getattr(context, intensity)
    _light = point_light(_position, _intensity)
    setattr(context, light, _light)
Ejemplo n.º 8
0
import argparse
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):