1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/PyGmy/scene.py Sun Oct 01 00:57:02 2006 +0000
1.3 @@ -0,0 +1,66 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +An example scene from...
1.8 +
1.9 +http://www.pawfal.org/index.php?page=PyGmy
1.10 +"""
1.11 +
1.12 +import math
1.13 +from ppygmy import *
1.14 +import sys
1.15 +
1.16 +class everythingshader(shader):
1.17 + def __init__(self):
1.18 + pass
1.19 +
1.20 + def shade(self,shaderinfo):
1.21 + col = shader.shade(self,shaderinfo)
1.22 + ref = self.getreflected(shaderinfo)
1.23 + col = col*0.5+ref*0.5
1.24 + return col*self.doocclusion(10,shaderinfo)
1.25 +
1.26 +class spotshader(shader):
1.27 + def __init__(self):
1.28 + pass
1.29 +
1.30 + def shade(self,shaderinfo):
1.31 + col = shader.shade(self,shaderinfo)
1.32 + position=shaderinfo["position"]
1.33 + jitter=(math.sin(position.x)+math.cos(position.z))
1.34 + if jitter>0.5: col=col/2
1.35 + ref = self.getreflected(shaderinfo)
1.36 + return ref*0.5+col*0.5*self.doocclusion(10,shaderinfo)
1.37 +
1.38 +if __name__ == "__main__":
1.39 + w = world(300,200)
1.40 + numballs=10.0
1.41 + offset = vec(0,-5,55)
1.42 + rad=12.0
1.43 + radperball=(2*3.141)/numballs
1.44 +
1.45 + for i in range(0,numballs):
1.46 + x=sin(0.3+radperball*float(i))*rad
1.47 + y=cos(0.3+radperball*float(i))*rad
1.48 + w.objects.append(sphere(vec(x,0,y)+offset,2,everythingshader()))
1.49 +
1.50 + w.objects.append(sphere(vec(3,3,0)+offset,5,everythingshader()))
1.51 + w.objects.append(plane(vec(0,1,0),7,spotshader()))
1.52 + w.lights.append(parallellight(vec(1,1,-1),vec(0.3,0.9,0.1)))
1.53 + w.lights.append(pointlight(vec(5,100,-5),vec(0.5,0.5,1)))
1.54 +
1.55 + if len(sys.argv) > 1:
1.56 + if "--help" in sys.argv:
1.57 + print "Specify a limit to the number of processes."
1.58 + print "For example:"
1.59 + print "python", sys.argv[0], "4"
1.60 + sys.exit(1)
1.61 + else:
1.62 + limit = int(sys.argv[1])
1.63 + else:
1.64 + limit = 1
1.65 +
1.66 + print "Number of processes:", limit
1.67 + w.render("test.tif", limit)
1.68 +
1.69 +# vim: tabstop=4 expandtab shiftwidth=4