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