from raytracer.matrices import scaling, rotation_y, rotation_x, translation, view_transform from raytracer.patterns import CheckersPattern from raytracer.scene import World 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)
def test_checker_x(): p = CheckersPattern(white, black) assert p.pattern_at(Point(0, 0, 0)) == white assert p.pattern_at(Point(0.99, 0, 0)) == white assert p.pattern_at(Point(1.01, 0, 0)) == black
def test_checkers_should_repeat_in_z(self): pattern = CheckersPattern(Color.white(), Color.black()) assert pattern.pattern_at(Point(0, 0, 0)) == Color.white() assert pattern.pattern_at(Point(0, 0, 0.99)) == Color.white() assert pattern.pattern_at(Point(0, 0, 1.01)) == Color.black()
Translation, Scaling, Color, Point, ViewTransform, Vector, ) from raytracer.patterns import CheckersPattern, StripePattern from raytracer.lights import PointLight from raytracer.camera import Camera from raytracer.world import World import math floor = Plane() floor.material.color = Color(1.0, 0.9, 0.9) floor.material.pattern = CheckersPattern(Color(1, 1, 1), Color(0, 0, 0)) floor.material.reflective = 0.5 floor.material.specular = 0 middle = Sphere() middle.set_transform(Translation(-0.5, 1, 0.5)) middle.material.transparency = 0.9 middle.material.diffuse = 0.1 middle.material.reflective = 0.9 middle.material.refractive_index = 1.5 middle.material.specular = 1 middle.material.shininess = 300 right = Sphere() right.set_transform(Translation(1.5, 0.5, -0.5) * Scaling(0.5, 1, 0.5)) right.material.pattern = StripePattern(Color(1, 1, 1), Color(0, 1, 0))