pprocess

examples/PyGmy/scene.py

71:71793e467e7d
2007-01-14 paulb [project @ 2007-01-14 23:03:28 by paulb] Added more documentation resources.
     1 #!/usr/bin/env python     2      3 """     4 An example scene from...     5      6 http://www.pawfal.org/index.php?page=PyGmy     7 """     8      9 import math    10 from ppygmy import *    11 import sys    12     13 class everythingshader(shader):    14     def __init__(self):    15         pass    16       17     def shade(self,shaderinfo):    18         col = shader.shade(self,shaderinfo)    19         ref = self.getreflected(shaderinfo)    20         col = col*0.5+ref*0.5    21         return col*self.doocclusion(10,shaderinfo)    22     23 class spotshader(shader):    24     def __init__(self):    25         pass    26       27     def shade(self,shaderinfo):    28         col = shader.shade(self,shaderinfo)    29         position=shaderinfo["position"]    30         jitter=(math.sin(position.x)+math.cos(position.z))    31         if jitter>0.5: col=col/2    32         ref = self.getreflected(shaderinfo)    33         return ref*0.5+col*0.5*self.doocclusion(10,shaderinfo)    34     35 if __name__ == "__main__":    36     w = world(300,200)    37     numballs=10.0    38     offset = vec(0,-5,55)    39     rad=12.0    40     radperball=(2*3.141)/numballs    41     42     for i in range(0,int(numballs)):    43         x=sin(0.3+radperball*float(i))*rad    44         y=cos(0.3+radperball*float(i))*rad    45         w.objects.append(sphere(vec(x,0,y)+offset,2,everythingshader()))    46             47     w.objects.append(sphere(vec(3,3,0)+offset,5,everythingshader()))    48     w.objects.append(plane(vec(0,1,0),7,spotshader()))    49     w.lights.append(parallellight(vec(1,1,-1),vec(0.3,0.9,0.1)))    50     w.lights.append(pointlight(vec(5,100,-5),vec(0.5,0.5,1)))    51     52     if len(sys.argv) > 1:    53         if "--help" in sys.argv:    54             print "Specify a limit to the number of processes."    55             print "For example:"    56             print "python", sys.argv[0], "4"    57             sys.exit(1)    58         else:    59             limit = int(sys.argv[1])    60     else:    61         limit = 1    62     63     print "Number of processes:", limit    64     w.render("test.tif", limit)    65     66 # vim: tabstop=4 expandtab shiftwidth=4