demos/demo_PIL.py
branchpyrit
changeset 90 f6a72eb99631
child 96 9eb71e76c7fd
equal deleted inserted replaced
89:fcf1487b398b 90:f6a72eb99631
       
     1 #!/usr/bin/python
       
     2 
       
     3 from pyrit import *
       
     4 import Image
       
     5 
       
     6 rt = Raytracer()
       
     7 top = KdTree()
       
     8 rt.setTop(top)
       
     9 rt.setCamera(Camera())
       
    10 
       
    11 light1 = Light(position=(0.0, 5.0, -5.0), colour=(0.7, 0.3, 0.6))
       
    12 rt.addLight(light1)
       
    13 
       
    14 light2 = Light(position=(-2.0, 10.0, -2.0), colour=(0.4, 0.6, 0.3))
       
    15 rt.addLight(light2)
       
    16 
       
    17 mat0 = Material(colour=(0.7, 0.7, 0.7))
       
    18 
       
    19 box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.0, 20.0), material=mat0)
       
    20 rt.addShape(box)
       
    21 
       
    22 mat1 = Material(colour=(1.0, 0.0, 0.0))
       
    23 bigsphere = Sphere(centre=(3.0, 2.0, -7.0), radius=3.0, material=mat1)
       
    24 rt.addShape(bigsphere)
       
    25 
       
    26 mat2 = Material(colour=(0.0, 1.0, 0.0))
       
    27 smallsphere = Sphere(centre=(-5.5, 1.5, -8.0), radius=2.0, material=mat2)
       
    28 rt.addShape(smallsphere)
       
    29 
       
    30 mat3 = Material(colour=(0.0, 0.0, 1.0))
       
    31 tinysphere = Sphere(centre=(-1.2, 0.0, -2.0), radius=0.5, material=mat3)
       
    32 rt.addShape(tinysphere)
       
    33 
       
    34 top.optimize()
       
    35 imagesize = (800, 600)
       
    36 sampler = DefaultSampler(imagesize)
       
    37 rt.setSampler(sampler)
       
    38 rt.render()
       
    39 pixmap = sampler.getPixmap()
       
    40 data = pixmap.getCharData()
       
    41 img = Image.fromstring("RGB", imagesize, data)
       
    42 img.save('demo_PIL.png')