from raytracer.shapes import Sphere, Plane
from raytracer.tuples import Color, Point, Vector

if __name__ == '__main__':
    floor = Plane()
    floor.material = Material()
    floor.material.color = Color(1, 0.9, 0.9)
    floor.material.specular = 0

    middle = Sphere()
    middle.transformation = translation(-0.5, 1, 0.5)
    middle.material = Material()
    middle.material.pattern = CheckersPattern(Color(0.1, 1, 0.5),
                                              Color(1, 0, 0))
    middle.material.pattern.transformation = scaling(0.25, 0.25,
                                                     0.5) * rotation_y(pi / 4)
    middle.material.diffuse = 0.7
    middle.material.specular = 0.3

    right = Sphere()
    right.transformation = 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

    left = Sphere()
    left.transformation = 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)
 def test_construct_ray_when_camera_is_transformed(self):
     c = Camera(201, 101, pi / 2)
     c.transformation = rotation_y(pi / 4) * translation(0, -2, 5)
     r = c.ray_for_pixel(100, 50)
     assert r.origin == Point(0, 2, -5)
     assert r.direction == Vector(sqrt(2) / 2, 0, -sqrt(2) / 2)
from raytracer.lights import PointLight
from raytracer.patterns import *
from raytracer.matrices import scaling, rotation_x, rotation_y, rotation_z, translation, view_transform
from raytracer.scene import World
from raytracer.shapes import Cylinder, Plane
from raytracer.tuples import Color, Point, Vector

if __name__ == '__main__':
    floor = Plane()
    floor.material.color = Color(.8, .8, .8)
    floor.material.reflective = .2

    cylinder = Cylinder(closed=True)
    cylinder.maximum = 0.25
    cylinder.material.color = Color(.8, 0, 0)
    cylinder.material.reflective = .6
    cylinder.transformation = translation(0, 1, 0)

    world = World()
    world.add(floor, cylinder)
    world.light_source = PointLight(Point(-10, 10, -10), Color.white())

    camera = Camera(160, 120, pi / 3)
    camera.transformation = view_transform(Point(0, 1.5, -5), Point(
        0, 1, 0), Vector(0, 1, 0)) * rotation_y(-pi / 4) * rotation_x(-pi / 6)

    canvas = camera.render(world)

    write_ppm_to_file(canvas.to_ppm(),
                      f'..{sep}..{sep}resources{sep}cylinders.ppm')
from raytracer.canvas import write_ppm_to_file
from raytracer.lights import PointLight
from raytracer.patterns import *
from raytracer.matrices import scaling, rotation_y, rotation_z, translation, view_transform
from raytracer.scene import World
from raytracer.shapes import Cube, Plane
from raytracer.tuples import Color, Point, Vector

if __name__ == '__main__':
    floor = Plane()
    floor.material.color = Color(.8, .8, .8)
    floor.material.reflective = .2

    cube = Cube()
    cube.material.color = Color(.8, 0, 0)
    cube.material.reflective = .6
    cube.transformation = translation(0, 1, 0) * rotation_y(pi / 4)

    world = World()
    world.add(floor, cube)
    world.light_source = PointLight(Point(-10, 10, -10), Color.white())

    camera = Camera(160, 120, pi / 3)
    camera.transformation = view_transform(Point(0, 1.5, -5), Point(0, 1, 0),
                                           Vector(0, 1, 0))

    canvas = camera.render(world)

    write_ppm_to_file(canvas.to_ppm(),
                      f'..{sep}..{sep}resources{sep}cubes.ppm')
Пример #5
0
 def test_rotate_point_around_y_axis(self):
     p = Point(0, 0, 1)
     half_quarter = rotation_y(math.pi / 4)
     full_quarter = rotation_y(math.pi / 2)
     assert half_quarter * p == Point(math.sqrt(2) / 2, 0, math.sqrt(2) / 2)
     assert full_quarter * p == Point(1, 0, 0)
from raytracer.materials import Material
from raytracer.matrices import scaling, rotation_y, rotation_x, translation, view_transform
from raytracer.scene import World
from raytracer.shapes import Sphere
from raytracer.tuples import Color, Point, Vector

if __name__ == '__main__':
    floor = Sphere()
    floor.transformation = scaling(10, 0.01, 10)
    floor.material = Material()
    floor.material.color = Color(1, 0.9, 0.9)
    floor.material.specular = 0

    left_wall = Sphere()
    left_wall.transformation = translation(0, 0, 5) * \
        rotation_y(-pi / 4) * rotation_x(pi / 2) * \
        scaling(10, 0.01, 10)
    left_wall.material = floor.material

    right_wall = Sphere()
    right_wall.transformation = translation(0, 0, 5) * \
        rotation_y(pi / 4) * rotation_x(pi / 2) * \
        scaling(10, 0.01, 10)
    right_wall.material = floor.material

    middle = Sphere()
    middle.transformation = 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