-
Notifications
You must be signed in to change notification settings - Fork 0
/
world-test
executable file
·62 lines (52 loc) · 1.93 KB
/
world-test
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
#!/usr/bin/env python
from Sphere import Sphere
from Transformation import Scaling, Translation, Rotation_x, Rotation_y,\
ViewTransform
from Material import Material
from Tuple4 import Colour, Point, Vector
from math import pi
from Light import PointLight
from World import World
from Camera import Camera
world = World()
floor = Sphere()
floor.transform = Scaling(10, 0.01, 10)
floor.material = Material()
floor.material.colour = Colour(1, 0.9, 0.9)
floor.material.specular = 0
left_wall = Sphere()
left_wall.transform = Translation(0, 0, 5) *\
Rotation_y(-pi/4) * Rotation_x(pi/2) *\
Scaling(10, 0.01, 10)
left_wall.material = floor.material
right_wall = Sphere()
right_wall.transform = Translation(0, 0, 5) *\
Rotation_y(pi/4) * Rotation_x(pi/2) *\
Scaling(10, 0.01, 10)
right_wall.material = floor.material
middle = Sphere()
middle.transform = Translation(-0.5, 1, 0.5)
middle.material = Material()
middle.material.colour = Colour(0.1, 1, 0.5)
middle.material.diffuse = 0.7
middle.material.specular = 0.3
right = Sphere()
right.transform = Translation(1.5, 0.5, -0.5) * Scaling(0.5, 0.5, 0.5)
right.material = Material()
right.material.colour = Colour(0.5, 1, 0.1)
right.material.diffuse = 0.7
right.material.specular = 0.3
left = Sphere()
left.transform = Translation(-1.5, 0.33, -0.75) * Scaling(0.33, 0.33, 0.33)
left.material = Material()
left.material.colour = Colour(1, 0.8, 0.1)
left.material.diffuse = 0.7
left.material.specular = 0.3
world.objects += [floor, left_wall, right_wall, middle, right, left]
world.lights.append(PointLight(Point(-10, 10, -10), Colour(1, 1, 1)))
camera = Camera(160, 90, pi/3)
camera.transform = ViewTransform(Point(0, 0.5, -5),
Point(0, 0, 0),
Vector(0, 1, 0))
canvas = camera.render_world(world, False)
canvas.to_ppm_file("world-test.ppm")