# # functions # pmb 10/1/02 from visual import * # functions let you take some code that gets executed a lot # and just write it once def turnRed ( obj ): obj.color = color.red return def turnYellow (obj): obj.color= color.yellow return color.yellow ball = sphere ( pos= (3,0,0,) ) cube = box ( pos=(-3,0,0 ) ) while 1: # wait for mouse click if scene.mouse.clicked: # get the click- without this it never gets unclicked click = scene.mouse.getclick() # what got clicked? if scene.mouse.pick == ball: print "ball was clicked" turnRed(ball) # same for cube; elif is really else if elif scene.mouse.pick == cube: print "cube was clicked" if ( cube.color == color.red ): print "cube is ",turnYellow( cube ) else: turnRed(cube)