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 # Choose one of the ppygmy imports: 11 from ppygmy import * 12 #from ppygmy_pmap import * 13 import sys 14 15 class everythingshader(shader): 16 def __init__(self): 17 pass 18 19 def shade(self,shaderinfo): 20 col = shader.shade(self,shaderinfo) 21 ref = self.getreflected(shaderinfo) 22 col = col*0.5+ref*0.5 23 return col*self.doocclusion(10,shaderinfo) 24 25 class spotshader(shader): 26 def __init__(self): 27 pass 28 29 def shade(self,shaderinfo): 30 col = shader.shade(self,shaderinfo) 31 position=shaderinfo["position"] 32 jitter=(math.sin(position.x)+math.cos(position.z)) 33 if jitter>0.5: col=col/2 34 ref = self.getreflected(shaderinfo) 35 return ref*0.5+col*0.5*self.doocclusion(10,shaderinfo) 36 37 if __name__ == "__main__": 38 w = world(300,200) 39 numballs=10.0 40 offset = vec(0,-5,55) 41 rad=12.0 42 radperball=(2*3.141)/numballs 43 44 for i in range(0,int(numballs)): 45 x=sin(0.3+radperball*float(i))*rad 46 y=cos(0.3+radperball*float(i))*rad 47 w.objects.append(sphere(vec(x,0,y)+offset,2,everythingshader())) 48 49 w.objects.append(sphere(vec(3,3,0)+offset,5,everythingshader())) 50 w.objects.append(plane(vec(0,1,0),7,spotshader())) 51 w.lights.append(parallellight(vec(1,1,-1),vec(0.3,0.9,0.1))) 52 w.lights.append(pointlight(vec(5,100,-5),vec(0.5,0.5,1))) 53 54 if len(sys.argv) > 1: 55 if "--help" in sys.argv: 56 print "Specify a limit to the number of processes." 57 print "For example:" 58 print "python", sys.argv[0], "4" 59 sys.exit(1) 60 else: 61 limit = int(sys.argv[1]) 62 else: 63 limit = 1 64 65 print "Number of processes:", limit 66 w.render("test.tif", limit) 67 68 # vim: tabstop=4 expandtab shiftwidth=4