for y in range(canvas_pixels): world_y = half - pixel_size * y for x in range(canvas_pixels): world_x = -half + pixel_size * x pos = point(world_x, world_y, wall_z) r = ray(ray_origin, normalize(pos - ray_origin)) xs = intersect(shape, r) if hit(xs) is not None: pnt = position(r, xs[0].t) normal = normal_at(xs[0].object, pnt) eye = -r.direction color = lighting(xs[0].object.material, xs[0].object, light, pnt, eye, normal) write_pixel(canvas, x, y, color) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/sphere.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
right.material = material() right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 w.objects.append(right) left = sphere() left.transform = 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 w.objects.append(left) cam = camera(400, 200, pi / 3) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/planes.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
# shape.transform = shearing(1, 0, 0, 0, 0, 0) * scaling(0.5, 1, 1) start = time.time() print("Starting render...") for y in range(canvas_pixels): world_y = half - pixel_size * y for x in range(canvas_pixels): world_x = -half + pixel_size * x position = point(world_x, world_y, wall_z) r = ray(ray_origin, normalize(position - ray_origin)) xs = intersect(shape, r) if hit(xs) is not None: write_pixel(canvas, x, y, color) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/circle.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
color(0.8, 0.8, 0.2)) w.objects.append(right) left = sphere() left.transform = 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.reflective = 0.1 left.material.pattern = gradient_pattern(color(0.7, 0.5, 0.7), color(0, 0.8, 0.2)) w.objects.append(left) cam = camera(1600, 800, pi / 2) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/reflections.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
color(0.8, 0.8, 0.2)) w.objects.append(right) left = cube() left.transform = 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.reflective = 0.1 left.material.pattern = gradient_pattern(color(0.7, 0.5, 0.7), color(0, 0.8, 0.2)) w.objects.append(left) cam = camera(1600, 800, pi / 2) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/cubes.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
right.material = material() right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 w.objects.append(right) left = sphere() left.transform = 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 w.objects.append(left) cam = camera(200, 100, pi / 3) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/shawdows.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
def step_impl(context): context.ppm = canvas_to_ppm(context.c)
from hexagon import hexagon from matrix import view_transform from tuple import color, point, point_light, vector from world import world if __name__ == "__main__": start = time.time() print("Starting render...") w = world() w.light = point_light(point(-10, 10, -10), color(1, 1, 1)) hex = hexagon() w.objects.append(hex) cam = camera(1600, 800, pi / 2) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/groups.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
def step_impl(context): context.ppm = list(canvas.canvas_to_ppm(context.c))
right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 right.material.pattern = ring_pattern(color(0.2, 0.5, 0.7), color(0.8, 0.8, 0.2)) w.objects.append(right) left = sphere() left.transform = 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 = gradient_pattern(color(0.7, 0.5, 0.7), color(0, 0.8, 0.2)) w.objects.append(left) cam = camera(1600, 800, pi / 3) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/patterns.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")
right.material = material() right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 w.objects.append(right) left = sphere() left.transform = 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 w.objects.append(left) cam = camera(200, 100, pi / 3) cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) canvas = render(cam, w) end = time.time() print("Finished render.") print(str(round(end - start, 2)) + "s") start = time.time() print("Start writing file...") canvas_to_ppm(canvas).write_file("images/scene.ppm") end = time.time() print("Finished writing file.") print(str(round(end - start, 2)) + "s")