demos/spheres_shadow.py
author Radek Brich <radek.brich@devl.cz>
Tue, 29 Apr 2008 13:56:29 +0200
branchpyrit
changeset 89 fcf1487b398b
parent 75 20dee9819b17
child 90 f6a72eb99631
permissions -rwxr-xr-x
use SSE for float to char image buffer conversion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
     5
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
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
     7
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
     8
light1 = Light(position=(0.0, 5.0, -5.0), colour=(0.7, 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
     9
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
    10
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
    11
light2 = Light(position=(-2.0, 10.0, -2.0), colour=(0.4, 0.6, 0.3))
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    12
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
    13
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
mat0 = Material(colour=(0.7, 0.7, 0.7))
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
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
    16
box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.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
    17
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
    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
mat1 = Material(colour=(1.0, 0.0, 0.0))
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
    20
bigsphere = Sphere(centre=(3.0, 2.0, -7.0), radius=3.0, material=mat1)
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    21
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
    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
mat2 = Material(colour=(0.0, 1.0, 0.0))
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
    24
smallsphere = Sphere(centre=(-5.5, 1.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
    25
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
    26
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
mat3 = Material(colour=(0.0, 0.0, 1.0))
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
    28
tinysphere = Sphere(centre=(-1.2, 0.0, -2.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
    29
rt.addShape(tinysphere)
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
    30
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
imagesize = (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
    32
data = rt.render(imagesize)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
img = Image.fromstring("RGB", imagesize, data)
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
img.save('spheres_shadow.png')