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