demos/spheres_glass.py
author Radek Brich <radek.brich@devl.cz>
Thu, 10 Apr 2008 23:20:36 +0200
branchpyrit
changeset 65 242839c6d27d
parent 60 a23b5089b9c3
child 75 20dee9819b17
permissions -rwxr-xr-x
basic detection of compiler (GCC or ICC) and CPU capabilities try to detect Python path in Windows and allow direct specification through build option plus other build system fixes
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
#, 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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
     9
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
    10
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
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    13
light2 = Light(position=(-2.0, -4.0, -1.0), colour=(0.7, 1.0, 0.3))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    14
rt.addlight(light2)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    15
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    16
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
    17
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
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    20
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
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    24
mat1.setReflectivity(0.7)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    25
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
    26
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
    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)
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
    31
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
    32
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    33
mat3 = Material(colour=(0.9, 0.9, 1.0))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    37
for i in range(10):
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    38
	sph = Sphere(centre=(-5.0+i, -1.5, -4.0), radius=0.5, material=mat3)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
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')