-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaytracer.py
52 lines (40 loc) · 1.99 KB
/
Raytracer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from Vector3D import Vector3D
from Color import Color
from Material import MaterialMonochrome, MaterialCheckered
from Light import PointLight
from Object3D import Object3DSphere
from Scene import Scene
from Engine import RenderEngine
import time
def main():
# Render Setting
WIDTH = 1280
HEIGHT = 720
SHADOWS = True
SHADED = True
timerStart = time.time()
camera = Vector3D(0, -0.3, -1)
objects = [
Object3DSphere(Vector3D(0, 10000.5, 1), 10000.0, MaterialMonochrome(Color.HexToRgb("#111111"), ambient = 0.2, reflection = 0.2)),
Object3DSphere(Vector3D(-0.25, 0, 0.6), 0.5, MaterialMonochrome(Color.HexToRgb("#FF0000"))),
Object3DSphere(Vector3D(-0.15, -0.1, 0.15), 0.1, MaterialMonochrome(Color.HexToRgb("#FFFFFF"), reflection = 0.01)),
Object3DSphere(Vector3D(-0.12, -0.12, 0.05), 0.05, MaterialMonochrome(Color.HexToRgb("#000000"), reflection = 0.01)),
Object3DSphere(Vector3D(-0.4, -0.1, 0.15), 0.1, MaterialMonochrome(Color.HexToRgb("#FFFFFF"), reflection = 0.01)),
Object3DSphere(Vector3D(-0.37, -0.12, 0.05), 0.05, MaterialMonochrome(Color.HexToRgb("#000000"), reflection = 0.01)),
Object3DSphere(Vector3D(1.3, -0.15, 1), 0.75, MaterialMonochrome(Color.HexToRgb("#FFFF00"))),
Object3DSphere(Vector3D(1, -1.85, 8), 0.75, MaterialMonochrome(Color.HexToRgb("#00FF00"))),
Object3DSphere(Vector3D(-5, 3, 5), 5, MaterialCheckered(Color.HexToRgb("#0000FF"), Color.HexToRgb("#FFFFFF"))),
]
lights = [
PointLight(Vector3D(-1, -15, -1), Color.HexToRgb("#FFFFFF")),
PointLight(Vector3D(2, -1, -10), Color.HexToRgb("#FFACF4"))
]
scene = Scene(camera, objects, lights, WIDTH, HEIGHT)
engine = RenderEngine()
image = engine.render(scene, SHADED, SHADOWS)
with open("# - Rendered Image.ppm", "w") as imgFile:
image.exportImage(imgFile)
timerEnd = time.time()
print("Time elapsed :", round(timerEnd - timerStart, 2), " seconds")
if __name__ == "__main__":
main()