demos/demo.py
branchpyrit
changeset 14 fc18ac4833f2
parent 6 d8d596d26f25
child 19 4e0955fca797
equal deleted inserted replaced
13:fbd1d2f7d94e 14:fc18ac4833f2
     1 #!/usr/bin/python
     1 #!/usr/bin/python
     2 
     2 
     3 import sys
     3 import sys
     4 sys.path.append("..")
     4 sys.path.append("..")
     5 
     5 
     6 from raytracer import Raytracer, Material, Plane, Sphere, Light
     6 from raytracer import Raytracer, Material, Box, Sphere, Light
     7 #, SphericalLight
     7 #, SphericalLight
     8 import Image
     8 import Image
     9 
     9 
    10 rt = Raytracer()
    10 rt = Raytracer()
    11 
    11 
    15 #light2 = SphericalLight(position=(-2.0, 5.0, 1.0), radius=3.0, colour=(0.7, 1.0, 0.3))
    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, -5.0, 1.0), colour=(0.7, 1.0, 0.3))
    16 light2 = Light(position=(-2.0, -5.0, 1.0), colour=(0.7, 1.0, 0.3))
    17 rt.addlight(light2)
    17 rt.addlight(light2)
    18 
    18 
    19 mat0 = Material(colour=(0.1, 0.2, 0.9))
    19 mat0 = Material(colour=(0.1, 0.2, 0.9))
    20 plane = Plane(normal=(0.0, 1.0, 0.0), d=1.0, material=mat0)
    20 box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.0, 20.0), material=mat0)
    21 rt.addshape(plane)
    21 rt.addshape(box)
    22 
    22 
    23 mat1 = Material(colour=(1.0, 0.2, 0.1))
    23 mat1 = Material(colour=(1.0, 0.2, 0.1))
    24 bigsphere = Sphere(centre=(2.0, 2.0, 5.0), radius=2.5, material=mat1)
    24 bigsphere = Sphere(centre=(2.0, 2.0, 5.0), radius=2.5, material=mat1)
    25 #      reflection=0.6)
    25 #      reflection=0.6)
    26 rt.addshape(bigsphere)
    26 rt.addshape(bigsphere)
    40 #      rt.addshape(sph)
    40 #      rt.addshape(sph)
    41 
    41 
    42 rendersize = (800, 600)
    42 rendersize = (800, 600)
    43 data = rt.render(rendersize)
    43 data = rt.render(rendersize)
    44 img = Image.fromstring("RGB", rendersize, data)
    44 img = Image.fromstring("RGB", rendersize, data)
    45 img.save('out.png')
    45 img.save('demo.png')