コード例 #1
0
 def test_render_world_with_camera(self, default_world):
     w = default_world
     c = Camera(11, 11, pi / 2)
     _from = Point(0, 0, -5)
     to = Point(0, 0, 0)
     up = Vector(0, 2, 0)
     c.transformation = view_transform(_from, to, up)
     image = c.render(w)
     assert image.pixel_at(5, 5) == Color(0.38066, 0.47583, 0.2855)
コード例 #2
0
ファイル: test_camera.py プロジェクト: techneklept/pyraytrace
 def test_rendering_world_with_camera(self):
     w = World.default()
     c = Camera(11, 11, math.pi / 2)
     frm = Point(0, 0, -5)
     to = Point(0, 0, 0)
     up = Vector(0, 1, 0)
     c.transform = ViewTransform(frm, to, up)
     image = c.render(w)
     self.assertEqual(image.pixel_at(5, 5), Color(0.38066, 0.47583, 0.2855))
コード例 #3
0
ファイル: test_camera.py プロジェクト: tobycyanide/pytracer
def test_render():
    w = World.default()
    c = Camera(11, 11, math.pi / 2)
    f = Point(0, 0, -5)
    to = Point(0, 0, 0)
    up = Vector(0, 1, 0)
    c.transform = ViewTransform(f, to, up)
    image = c.render(w)
    assert image.read_pixel(5, 5) == Color(0.38066, 0.47583, 0.2855)
コード例 #4
0
from math import pi
from os import sep
from raytracer.camera import Camera
from raytracer.canvas import write_ppm_to_file
from raytracer.lights import PointLight
from raytracer.matrices import *
from raytracer.obj_file import parse_obj_file
from raytracer.scene import World
from raytracer.tuples import Color, Point, Vector


def teapot():
    parser = parse_obj_file(f'..{sep}resources{sep}Sting-Sword-lowpoly.obj')
    return parser.obj_to_group()


if __name__ == '__main__':
    world = World()
    world.add(teapot())
    world.light_source = PointLight(Point(-5, 5, -5), Color.white())

    camera = Camera(150, 100, pi / 3)
    camera.transformation = view_transform(Point(0, 1.5, -10), Point(0, 1, 0),
                                           Vector(0, 1, 0))

    canvas = camera.render(world)

    write_ppm_to_file(canvas.to_ppm(),
                      f'..{sep}..{sep}resources{sep}sting.ppm')
コード例 #5
0
ファイル: teapot.py プロジェクト: tobycyanide/pytracer
from raytracer.parser import Parser
from raytracer.world import World
from raytracer.camera import Camera
from raytracer.lights import PointLight
from raytracer.base import Point, Color, ViewTransform, Vector
f = open("tests/obj_files/face.obj", "r")
p = Parser(f)
w = World()
w.objects.append(p.obj_to_group())
w.light = PointLight(Point(10, 5, 5), Color(1, 1, 1))
c = Camera(10, 10, 0.785)
c.transform = ViewTransform(Point(-6, 6, -10), Point(6, 0, 6),
                            Vector(-0.45, 1, 0))
canvas = c.render(w)
with open("images/triangl.ppm", "w") as f:
    f.write(canvas.to_ppm())
# This is wayyy too slow we're gonna need a triangle mesh or something