author | Radek Brich <radek.brich@devl.cz> |
Thu, 15 May 2008 00:07:25 +0200 | |
branch | pyrit |
changeset 96 | 9eb71e76c7fd |
parent 90 | f6a72eb99631 |
permissions | -rwxr-xr-x |
90
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
from pyrit import * |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
import Image |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
rt = Raytracer() |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
top = KdTree() |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
rt.setTop(top) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
rt.setCamera(Camera()) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
light1 = Light(position=(0.0, 5.0, -5.0), colour=(0.7, 0.3, 0.6)) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
rt.addLight(light1) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
light2 = Light(position=(-2.0, 10.0, -2.0), colour=(0.4, 0.6, 0.3)) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
rt.addLight(light2) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
mat0 = Material(colour=(0.7, 0.7, 0.7)) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.0, 20.0), material=mat0) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
rt.addShape(box) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
mat1 = Material(colour=(1.0, 0.0, 0.0)) |
96
9eb71e76c7fd
added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
23 |
bigsphere = Sphere(center=(3.0, 2.0, -7.0), radius=3.0, material=mat1) |
90
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
rt.addShape(bigsphere) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
mat2 = Material(colour=(0.0, 1.0, 0.0)) |
96
9eb71e76c7fd
added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
27 |
smallsphere = Sphere(center=(-5.5, 1.5, -8.0), radius=2.0, material=mat2) |
90
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
rt.addShape(smallsphere) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
mat3 = Material(colour=(0.0, 0.0, 1.0)) |
96
9eb71e76c7fd
added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
31 |
tinysphere = Sphere(center=(-1.2, 0.0, -2.0), radius=0.5, material=mat3) |
90
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
rt.addShape(tinysphere) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
|
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
top.optimize() |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
imagesize = (800, 600) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
sampler = DefaultSampler(imagesize) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
rt.setSampler(sampler) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
rt.render() |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
pixmap = sampler.getPixmap() |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
data = pixmap.getCharData() |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
img = Image.fromstring("RGB", imagesize, data) |
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
img.save('demo_PIL.png') |