demos/spheres_shadow.py
branchpyrit
changeset 75 20dee9819b17
parent 60 a23b5089b9c3
child 90 f6a72eb99631
equal deleted inserted replaced
74:09aedbf5f95f 75:20dee9819b17
     4 import Image
     4 import Image
     5 
     5 
     6 rt = Raytracer()
     6 rt = Raytracer()
     7 
     7 
     8 light1 = Light(position=(0.0, 5.0, -5.0), colour=(0.7, 0.3, 0.6))
     8 light1 = Light(position=(0.0, 5.0, -5.0), colour=(0.7, 0.3, 0.6))
     9 rt.addlight(light1)
     9 rt.addLight(light1)
    10 
    10 
    11 light2 = Light(position=(-2.0, 10.0, -2.0), colour=(0.4, 0.6, 0.3))
    11 light2 = Light(position=(-2.0, 10.0, -2.0), colour=(0.4, 0.6, 0.3))
    12 rt.addlight(light2)
    12 rt.addLight(light2)
    13 
    13 
    14 mat0 = Material(colour=(0.7, 0.7, 0.7))
    14 mat0 = Material(colour=(0.7, 0.7, 0.7))
    15 
    15 
    16 box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.0, 20.0), material=mat0)
    16 box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.0, 20.0), material=mat0)
    17 rt.addshape(box)
    17 rt.addShape(box)
    18 
    18 
    19 mat1 = Material(colour=(1.0, 0.0, 0.0))
    19 mat1 = Material(colour=(1.0, 0.0, 0.0))
    20 bigsphere = Sphere(centre=(3.0, 2.0, -7.0), radius=3.0, material=mat1)
    20 bigsphere = Sphere(centre=(3.0, 2.0, -7.0), radius=3.0, material=mat1)
    21 rt.addshape(bigsphere)
    21 rt.addShape(bigsphere)
    22 
    22 
    23 mat2 = Material(colour=(0.0, 1.0, 0.0))
    23 mat2 = Material(colour=(0.0, 1.0, 0.0))
    24 smallsphere = Sphere(centre=(-5.5, 1.5, -8.0), radius=2.0, material=mat2)
    24 smallsphere = Sphere(centre=(-5.5, 1.5, -8.0), radius=2.0, material=mat2)
    25 rt.addshape(smallsphere)
    25 rt.addShape(smallsphere)
    26 
    26 
    27 mat3 = Material(colour=(0.0, 0.0, 1.0))
    27 mat3 = Material(colour=(0.0, 0.0, 1.0))
    28 tinysphere = Sphere(centre=(-1.2, 0.0, -2.0), radius=0.5, material=mat3)
    28 tinysphere = Sphere(centre=(-1.2, 0.0, -2.0), radius=0.5, material=mat3)
    29 rt.addshape(tinysphere)
    29 rt.addShape(tinysphere)
    30 
    30 
    31 imagesize = (800, 600)
    31 imagesize = (800, 600)
    32 data = rt.render(imagesize)
    32 data = rt.render(imagesize)
    33 img = Image.fromstring("RGB", imagesize, data)
    33 img = Image.fromstring("RGB", imagesize, data)
    34 img.save('spheres_shadow.png')
    34 img.save('spheres_shadow.png')