5 import Image |
5 import Image |
6 |
6 |
7 rt = Raytracer() |
7 rt = Raytracer() |
8 |
8 |
9 light1 = Light(position=(0.0, 4.0, -3.0), colour=(0.9, 0.3, 0.6)) |
9 light1 = Light(position=(0.0, 4.0, -3.0), colour=(0.9, 0.3, 0.6)) |
10 rt.addlight(light1) |
10 rt.addLight(light1) |
11 |
11 |
12 #light2 = SphericalLight(position=(-2.0, 5.0, 1.0), radius=3.0, colour=(0.7, 1.0, 0.3)) |
12 #light2 = SphericalLight(position=(-2.0, 5.0, 1.0), radius=3.0, colour=(0.7, 1.0, 0.3)) |
13 light2 = Light(position=(-2.0, -4.0, -1.0), colour=(0.7, 1.0, 0.3)) |
13 light2 = Light(position=(-2.0, -4.0, -1.0), colour=(0.7, 1.0, 0.3)) |
14 rt.addlight(light2) |
14 rt.addLight(light2) |
15 |
15 |
16 light2 = Light(position=(2.0, 5.0, 1.0), colour=(0.8, 0.9, 1.0)) |
16 light2 = Light(position=(2.0, 5.0, 1.0), colour=(0.8, 0.9, 1.0)) |
17 rt.addlight(light2) |
17 rt.addLight(light2) |
18 |
18 |
19 mat0 = Material(colour=(0.1, 0.2, 0.9)) |
19 mat0 = Material(colour=(0.1, 0.2, 0.9)) |
20 box = Box(L=(-20.0, -2.2, -20.0), H=(20.0, -2.0, 20.0), material=mat0) |
20 box = Box(L=(-20.0, -2.2, -20.0), H=(20.0, -2.0, 20.0), material=mat0) |
21 rt.addshape(box) |
21 rt.addShape(box) |
22 |
22 |
23 mat1 = Material(colour=(1.0, 0.2, 0.1)) |
23 mat1 = Material(colour=(1.0, 0.2, 0.1)) |
24 mat1.setReflectivity(0.7) |
24 mat1.setReflectivity(0.7) |
25 bigsphere = Sphere(centre=(2.0, 1.0, -5.0), radius=2.5, material=mat1) |
25 bigsphere = Sphere(centre=(2.0, 1.0, -5.0), radius=2.5, material=mat1) |
26 rt.addshape(bigsphere) |
26 rt.addShape(bigsphere) |
27 |
27 |
28 mat2 = Material(colour=(0.1, 0.4, 0.2)) |
28 mat2 = Material(colour=(0.1, 0.4, 0.2)) |
29 mat2.setReflectivity(0.6) |
29 mat2.setReflectivity(0.6) |
30 smallsphere = Sphere(centre=(-4.5, 0.5, -8.0), radius=2.0, material=mat2) |
30 smallsphere = Sphere(centre=(-4.5, 0.5, -8.0), radius=2.0, material=mat2) |
31 rt.addshape(smallsphere) |
31 rt.addShape(smallsphere) |
32 |
32 |
33 mat3 = Material(colour=(0.9, 0.9, 1.0)) |
33 mat3 = Material(colour=(0.9, 0.9, 1.0)) |
34 mat3.setPhong(0.2, 1.0, 0.2) |
34 mat3.setPhong(0.2, 1.0, 0.2) |
35 mat3.setTransmissivity(0.88) |
35 mat3.setTransmissivity(0.88) |
36 mat3.setReflectivity(0.1) |
36 mat3.setReflectivity(0.1) |
37 for i in range(10): |
37 for i in range(10): |
38 sph = Sphere(centre=(-5.0+i, -1.5, -4.0), radius=0.5, material=mat3) |
38 sph = Sphere(centre=(-5.0+i, -1.5, -4.0), radius=0.5, material=mat3) |
39 rt.addshape(sph) |
39 rt.addShape(sph) |
40 |
40 |
41 rendersize = (800, 600) |
41 rendersize = (800, 600) |
42 data = rt.render(rendersize) |
42 data = rt.render(rendersize) |
43 img = Image.fromstring("RGB", rendersize, data) |
43 img = Image.fromstring("RGB", rendersize, data) |
44 img.save('spheres_glass.png') |
44 img.save('spheres_glass.png') |