author | Radek Brich <radek.brich@devl.cz> |
Wed, 26 Mar 2008 17:03:38 +0100 | |
branch | pyrit |
changeset 48 | a4913301c626 |
parent 31 | b4e09433934a |
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 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
import sys |
24
d0d76e8a5203
new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
4 |
sys.path.append(open('ModulePath').read().strip()) |
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
|
5 |
|
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
|
6 |
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
|
7 |
#, 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
|
8 |
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
|
9 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
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
|
11 |
|
31 | 12 |
light1 = Light(position=(0.0, 4.0, -3.0), colour=(0.9, 0.3, 0.6)) |
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
|
13 |
rt.addlight(light1) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
#light2 = SphericalLight(position=(-2.0, 5.0, 1.0), radius=3.0, colour=(0.7, 1.0, 0.3)) |
31 | 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)) |
|
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
|
20 |
rt.addlight(light2) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
|
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 |
mat0 = Material(colour=(0.1, 0.2, 0.9)) |
31 | 23 |
box = Box(L=(-20.0, -2.2, -20.0), H=(20.0, -2.0, 20.0), material=mat0) |
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
|
24 |
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
|
25 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
mat1 = Material(colour=(1.0, 0.2, 0.1)) |
31 | 27 |
mat1.setReflectivity(0.7) |
28 |
bigsphere = Sphere(centre=(2.0, 1.0, -5.0), radius=2.5, material=mat1) |
|
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
|
29 |
# reflection=0.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
|
30 |
rt.addshape(bigsphere) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
|
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 |
mat2 = Material(colour=(0.1, 0.7, 1.0)) |
31 | 33 |
smallsphere = Sphere(centre=(-5.5, 0.5, -8.0), radius=2.0, material=mat2) |
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
|
34 |
# reflection=1.0, diffuse=0.1) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
rt.addshape(smallsphere) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
|
31 | 37 |
mat3 = Material(colour=(0.9, 0.9, 1.0)) |
38 |
mat3.setPhong(0.2, 1.0, 0.2) |
|
39 |
mat3.setTransmissivity(0.9) |
|
40 |
mat3.setReflectivity(0.0) |
|
41 |
for i in range(10): |
|
42 |
sph = Sphere(centre=(-5.0+i, -1.5, -4.0), radius=0.5, material=mat3) |
|
43 |
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
|
44 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
img = Image.fromstring("RGB", rendersize, data) |
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
|
48 |
img.save('demo.png') |