def main(): shape = ClippedShape(crooked_plane()) #shape.transform = ReflectionXZ() shape.material = Material() shape.material.color = Color(1, .2, 1) objects = (shape, ) draw_objects(objects)
def main(): logging.basicConfig( level=logging.INFO, format= '%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(name)s %(message)s' ) shape = ClippedShape(CrookedPlane()) shape.material = Material() shape.material.color = Color(1, .2, 1) #shape.material.pattern = gradient_pattern(BLUE, GREEN) #shape.material.pattern.transform = Scaling(4, 2, 2) objects = (shape, ) rad = 6 camera_height = .8 * rad frames = [] for t in np.arange(0, math.pi, .1 * math.pi): logging.info("New Frame %s", t) camera_position = Point(rad * math.cos(t), rad * math.sin(t), camera_height) vt = view_transform(camera_position, Point(0, 0, 0), Vector(0, 0, 1)) canvas = make_single_frame(objects, vt) frames.append(canvas._image) imageio.mimsave("examples/crooked_plane.gif", frames, duration=0.25)
def main(resolution): logging.basicConfig( level=logging.INFO, format= '%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(name)s %(message)s' ) shape = ClippedShape(CrookedPlane()) shape.material = Material() shape.material.color = Color(1, .2, 1) shape.material.transparency = 1.0 shape.material.refractive_index = 1.5 objects = (shape, ) rad = 6 camera_height = .8 * rad frames = [] for t in np.arange(0, math.pi, .1 * math.pi): logging.info("New Frame %s", t) camera_position = Point(rad * math.cos(t), rad * math.sin(t), camera_height) vt = view_transform(camera_position, Point(0, 0, 0), Vector(0, 0, 1)) canvas = make_single_frame(objects, vt, resolution) frames.append(canvas._image) path = Path(__file__).parent / "chap11.gif" imageio.mimsave(str(path), frames, duration=0.25)
def make_middle(): middle = set_transform(Sphere(), 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 return middle
def floor_material(): material = Material() material.color = Color(1, .9, .9) material.specular = 0 material.pattern = stripe_pattern(RED, BLUE) material.pattern.transform = Scaling(.2, .2, .2) * rotation_z(math.pi / 4) return material
def make_right(): right = set_transform(Sphere(), 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 return right
def make_left(): left = set_transform( Sphere(), 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) left.material.diffuse = 0.7 left.material.specular = 0.3 return left
def make_middle(): middle = set_transform(Sphere(), 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 middle.material.pattern = gradient_pattern(BLUE, GREEN) middle.material.pattern.transform = Scaling(.2, .2, .2) return middle
def make_left(): left = set_transform( Sphere(), 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) left.material.diffuse = 0.7 left.material.specular = 0.3 left.material.pattern = checkers_pattern(WHITE, BLACK) return left
def make_right(): right = set_transform(Sphere(), 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 right.material.pattern = ring_pattern(GREEN, BLACK) right.material.pattern.transform = Scaling(.2, .2, .2) * rotation_x( math.pi / 2) return right
def step_impl(context, m): _m = Material() setattr(context, m, _m)
def floor_material(): material = Material() material.color = Color(1, .9, .9) material.specular = 0 return material
def __init__(self, material=None): self.material = Material()
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): spot_on_wall = Point(world_x, world_y, wall_z) ray = Ray(ray_origin, normalize(spot_on_wall - ray_origin))