開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
- GIMP (ビットマップ画像編集・加工ソフトウェア、PPM形式(portable pixmap)の画像用)
The Ray Tracer Challenge: A Test-Driven Guide to Your First 3D Renderer (Jamis Buck(著)、Pragmatic Bookshelf)、Chapter 13(Cylinders)のPutting It Together(191)を取り組んでみる。
コード
Python 3
#!/usr/bin/env python3 import math import time from tuples import Point, Vector, Color from planes import Plane from cones import Cone from spheres import Sphere from materials import Material from camera import Camera from lights import Light from world import World from transformations import translation, scaling, view_transform from transformations import rotation_x, rotation_y, rotation_z print('ファイル名, rendering time(秒)') width = 250 height = 125 wall1 = Plane(material=Material(color=Color(0, 0, 1)), transform=translation(0, 0, 7) * rotation_y(-math.pi / 4) * rotation_x(math.pi / 2)) wall2 = Plane(material=Material(color=Color(1, 0, 0)), transform=translation(0, 0, 7) * rotation_y(math.pi / 4) * rotation_x(math.pi / 2)) floor = Plane(material=Material(Color(0, 1, 0)), transform=translation(0, -1, 0)) beige = Color(*[n / 255 for n in [245, 245, 220]]) cone = Cone(material=Material(color=beige), transform=translation(0, -1, 0) * scaling(0.5, 1, 0.5), minimum=0, maximum=1) colors = [Color(*[n / 255 for n in [96, 45, 29]]), Color(*[n / 255 for n in [227, 134, 143]]), Color(1, 1, 1)] spheres = [Sphere(material=Material(color=color), transform=translation(0, i * 0.8 + 0.4, 0) * scaling(0.5, 0.5, 0.5)) for i, color in enumerate(colors)] camera = Camera(width, height, math.pi / 2, transform=view_transform(Point(0, 1.5, -5), Point(0, 1, 0), Vector(0, 1, 0))) world = World([wall1, wall2, floor, cone] + spheres, Light(Point(-10, 10, -10), Color(1, 1, 1))) start = time.time() canvas = camera.render(world) s = time.time() - start with open(f'sample11.ppm', 'w') as f: canvas.to_ppm(f) print(f'sample11.ppm,{s}')
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
C:\Users\...>py sample5.py ファイル名, rendering time(秒) sample11.ppm,310.4135353565216 C:\Users\...>
0 コメント:
コメントを投稿