demos/demo.py
author Radek Brich <radek.brich@devl.cz>
Sat, 29 Mar 2008 12:09:50 +0100
branchpyrit
changeset 55 f6d75ae82c88
parent 31 b4e09433934a
permissions -rwxr-xr-x
fix bugs
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
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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    16
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
    17
rt.addlight(light2)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    18
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    27
mat1.setReflectivity(0.7)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    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
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    37
mat3 = Material(colour=(0.9, 0.9, 1.0))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    38
mat3.setPhong(0.2, 1.0, 0.2)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    39
mat3.setTransmissivity(0.9)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    40
mat3.setReflectivity(0.0)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    41
for i in range(10):
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    42
	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
    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')