#! /usr/bin/env python
from OpenGLContext import testingcontext BaseContext = testingcontext.getInteractive()
from OpenGLContext.scenegraph.basenodes import * from OpenGLContext.arrays import pi import random
class TestContext( BaseContext ): angle = 0 def OnInit( self ): """Load the image on initial load of the application""" print """You should see an opaque sphere and a translucent cylinder with rotating lighting in three colours."""
dl = DirectionalLight( direction = (-10,-10,0), color= (0,1,0), )
pl = PointLight( location = (-2,2,2), color=(1,0,0), radius = 3, )
sl = SpotLight( location = (0,0,4), color = (0,0,1), direction = (0,0,-1), )
self.lights = [ dl,pl,sl, ]
self.lightTransform = Transform( DEF = 'Light-Transform', children = self.lights, )
interpolators = [ OrientationInterpolator( DEF = 'Light-Orient', key = [0,.25,.5,.75,1.0], keyValue = [ 0,1,0,0, 0,1,0,pi/2, 0,1,0,pi, 0,1,0,3*pi/2, 0,1,0,0 ], ), ScalarInterpolator( key = [0,.5,1], keyValue = [.25,1,.25], DEF = 'Intensity-Interp', ), TimeSensor( cycleInterval = 3.0, loop = True, DEF = 'Timer', ), ]
geometry = [ Shape( geometry = Sphere( ), appearance = Appearance( material = Material( diffuseColor=(1,1,1) ), ), ), Transform( translation = (-3,-.25,1.5), rotation = (0,1,0,.75), children = [ Shape( geometry = Teapot( size=1.5 ), appearance = Appearance( material = Material( shininess = .9, diffuseColor = (.3,.3,.3), specularColor = (1,1,0), ), ), ), ], ), Transform( translation = (1,-.5,2), rotation = (1,0,0,.5), children = [ Shape( geometry = Cylinder( ), appearance = Appearance( material = Material( diffuseColor=(1,1,1), shininess = .8, transparency = .3, ), ), ), ], ), ]
self.sg = sceneGraph( children = [ self.lightTransform, ] + geometry + interpolators, )
self.sg.addRoute( 'Timer','fraction_changed', 'Light-Orient','set_fraction' ) self.sg.addRoute( 'Light-Orient','value_changed', 'Light-Transform','set_rotation' )
self.sg.addRoute( 'Timer','fraction_changed', 'Intensity-Interp','set_fraction' ) self.sg.addRoute( 'Intensity-Interp','value_changed', self.onIntensity )
self.sg.addRoute( 'Timer','cycleTime', self.onCycle, )
def onCycle( self, **named ): for light in self.lights: if random.random() > .6: light.on = False else: light.on = True def onIntensity( self, value ): for light in self.lights: light.intensity = value if __name__ == "__main__": TestContext.ContextMainLoop()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4