Beispiel #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
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #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)
def step_impl(context, w):
    setattr(context, w, World())