author | Radek Brich <radek.brich@devl.cz> |
Wed, 23 Apr 2008 10:38:33 +0200 | |
branch | pyrit |
changeset 78 | 9569e9f35374 |
parent 75 | 20dee9819b17 |
child 90 | f6a72eb99631 |
permissions | -rwxr-xr-x |
1
e74bf781067e
use python-config, strip python version from demos, change [PyRit] to [pyrit] -- should use unix name everywhere
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
1 |
#!/usr/bin/python |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
14
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
3 |
from raytracer import Raytracer, Material, Box, Sphere, Light |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
#, SphericalLight |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
import Image |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
rt = Raytracer() |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
31 | 9 |
light1 = Light(position=(0.0, 4.0, -3.0), colour=(0.9, 0.3, 0.6)) |
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
10 |
rt.addLight(light1) |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
#light2 = SphericalLight(position=(-2.0, 5.0, 1.0), radius=3.0, colour=(0.7, 1.0, 0.3)) |
31 | 13 |
light2 = Light(position=(-2.0, -4.0, -1.0), colour=(0.7, 1.0, 0.3)) |
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
14 |
rt.addLight(light2) |
31 | 15 |
|
16 |
light2 = Light(position=(2.0, 5.0, 1.0), colour=(0.8, 0.9, 1.0)) |
|
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
17 |
rt.addLight(light2) |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
mat0 = Material(colour=(0.1, 0.2, 0.9)) |
31 | 20 |
box = Box(L=(-20.0, -2.2, -20.0), H=(20.0, -2.0, 20.0), material=mat0) |
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
21 |
rt.addShape(box) |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
mat1 = Material(colour=(1.0, 0.2, 0.1)) |
31 | 24 |
mat1.setReflectivity(0.7) |
25 |
bigsphere = Sphere(centre=(2.0, 1.0, -5.0), radius=2.5, material=mat1) |
|
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
26 |
rt.addShape(bigsphere) |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
|
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
28 |
mat2 = Material(colour=(0.1, 0.4, 0.2)) |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
29 |
mat2.setReflectivity(0.6) |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
30 |
smallsphere = Sphere(centre=(-4.5, 0.5, -8.0), radius=2.0, material=mat2) |
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
31 |
rt.addShape(smallsphere) |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
|
31 | 33 |
mat3 = Material(colour=(0.9, 0.9, 1.0)) |
34 |
mat3.setPhong(0.2, 1.0, 0.2) |
|
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
35 |
mat3.setTransmissivity(0.88) |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
36 |
mat3.setReflectivity(0.1) |
31 | 37 |
for i in range(10): |
38 |
sph = Sphere(centre=(-5.0+i, -1.5, -4.0), radius=0.5, material=mat3) |
|
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
39 |
rt.addShape(sph) |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
rendersize = (800, 600) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
data = rt.render(rendersize) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
img = Image.fromstring("RGB", rendersize, data) |
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
44 |
img.save('spheres_glass.png') |