demos/spheres_glass.py
branchpyrit
changeset 56 d4481fc43952
parent 31 b4e09433934a
child 60 a23b5089b9c3
equal deleted inserted replaced
55:f6d75ae82c88 56:d4481fc43952
       
     1 #!/usr/bin/python
       
     2 
       
     3 import sys
       
     4 sys.path.append(open('ModulePath').read().strip())
       
     5 
       
     6 from raytracer import Raytracer, Material, Box, Sphere, Light
       
     7 #, SphericalLight
       
     8 import Image
       
     9 
       
    10 rt = Raytracer()
       
    11 
       
    12 light1 = Light(position=(0.0, 4.0, -3.0), colour=(0.9, 0.3, 0.6))
       
    13 rt.addlight(light1)
       
    14 
       
    15 #light2 = SphericalLight(position=(-2.0, 5.0, 1.0), radius=3.0, colour=(0.7, 1.0, 0.3))
       
    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))
       
    20 rt.addlight(light2)
       
    21 
       
    22 mat0 = Material(colour=(0.1, 0.2, 0.9))
       
    23 box = Box(L=(-20.0, -2.2, -20.0), H=(20.0, -2.0, 20.0), material=mat0)
       
    24 rt.addshape(box)
       
    25 
       
    26 mat1 = Material(colour=(1.0, 0.2, 0.1))
       
    27 mat1.setReflectivity(0.7)
       
    28 bigsphere = Sphere(centre=(2.0, 1.0, -5.0), radius=2.5, material=mat1)
       
    29 rt.addshape(bigsphere)
       
    30 
       
    31 mat2 = Material(colour=(0.1, 0.4, 0.2))
       
    32 mat2.setReflectivity(0.6)
       
    33 smallsphere = Sphere(centre=(-4.5, 0.5, -8.0), radius=2.0, material=mat2)
       
    34 rt.addshape(smallsphere)
       
    35 
       
    36 mat3 = Material(colour=(0.9, 0.9, 1.0))
       
    37 mat3.setPhong(0.2, 1.0, 0.2)
       
    38 mat3.setTransmissivity(0.88)
       
    39 mat3.setReflectivity(0.1)
       
    40 for i in range(10):
       
    41 	sph = Sphere(centre=(-5.0+i, -1.5, -4.0), radius=0.5, material=mat3)
       
    42 	rt.addshape(sph)
       
    43 
       
    44 rendersize = (800, 600)
       
    45 data = rt.render(rendersize)
       
    46 img = Image.fromstring("RGB", rendersize, data)
       
    47 img.save('spheres_glass.png')