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