-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
68 lines (57 loc) · 1.95 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- encoding: utf-8 -*-
from renderer import Camera
from renderer import PointLight
from renderer import RayTracer
from renderer import Scene
from renderer.geometry import Plane
from renderer.geometry import Sphere
from renderer.geometry import Vector
from renderer.material import Color
from renderer.material import PhongMaterial
from renderer.material import CheckerboardMaterial
# render-settings
RECURSION_DEPTH = 2 # for reflections; should be >= 0
IMAGE_WIDTH = 800 # in pixels
IMAGE_HEIGHT = 600 # in pixels
COLOR_DEPTH = 8 # bit per color-channel
# color-constants
RED = Color(1.0, 0, 0)
GREEN = Color(0, 1.0, 0)
BLUE = Color(0, 0, 1.0)
BLACK = Color(0, 0, 0)
WHITE = Color(1, 1, 1)
# material-constants
MAT_RED = PhongMaterial(RED, reflection=0.2)
MAT_GREEN = PhongMaterial(GREEN, reflection=0.2)
MAT_BLUE = PhongMaterial(BLUE, reflection=0.2)
def createScene():
scene = Scene(BLACK)
scene += Sphere(Vector(2.5, 3, -10), 2, MAT_RED)
scene += Sphere(Vector(-2.5, 3, -10), 2, MAT_GREEN)
scene += Sphere(Vector(0, 7, -10), 2, MAT_BLUE)
scene += Plane(Vector(0, 0, 0), Vector(0, 1, 0), CheckerboardMaterial())
return scene
def createCamera():
position = Vector(0, 2, 10)
up = Vector(0, 1, 0)
center = Vector(0, 3, 0)
return Camera(45, position, up, center)
def createDefaultLight():
return [PointLight(Vector(30, 30, 10), WHITE)]
def createFunkyLights():
lights = []
lights.append(PointLight(Vector(-30, 30, 10), RED))
lights.append(PointLight(Vector(0, 30, 10), GREEN))
lights.append(PointLight(Vector(30, 30, 10), BLUE))
return lights
if __name__ == "__main__":
print "running renderer"
scene = createScene()
# lights = createDefaultLight()
lights = createFunkyLights()
for light in lights:
scene += light
camera = createCamera()
r = RayTracer(scene, camera)
camera.maxLevel = RECURSION_DEPTH
r.render(IMAGE_WIDTH, IMAGE_HEIGHT, COLOR_DEPTH).show()