from visual import * # # this file gets input from keyboard and does things # pmb 9/27/02 # set up a cube cubecolor = ( 0.5,0.5,0.5 ) cube = box () cube.color= cubecolor print dir(scene) # just go straight into main loop while 1: # this waits until a key is pushed # then prints the nameof the key # print "wait for getkey" s = scene.kb.getkey() print " getkey returned ",s # rotate cube based for arrow keys; note angle is in radians! if ( s == "left" ): cube.rotate( angle= pi/30, axis= ( 0,1,0), origin = (0,0,0) ) if ( s == "right" ): cube.rotate( angle= -pi/30, axis= ( 0,1,0), origin = (0,0,0) ) if ( s == "up" ): cube.rotate( angle= pi/30, axis= ( 1,0,0), origin = (0,0,0) ) if ( s == "down" ): cube.rotate( angle= -pi/30, axis= ( 1,0,0), origin = (0,0,0) ) # if +/- pressed, make cube lighter or darker if ( s == "+" ): cubecolor= ( cubecolor[0]+0.1, cubecolor[1]+0.1, cubecolor[2]+0.1 ) cube.color = cubecolor if ( s == "-" ): cubecolor= ( cubecolor[0]-0.1, cubecolor[1]-0.1, cubecolor[2]-0.1 ) cube.color = cubecolor # "r" makes cube redder if ( s == "r" ): cubecolor= ( cubecolor[0]+0.1, cubecolor[1], cubecolor[2] ) cube.color = cubecolor # "g" makes cube greener if ( s == "g" ): cubecolor= ( cubecolor[0], cubecolor[1]+0.1, cubecolor[2] ) cube.color = cubecolor # "b" makes cube bluer if ( s == "b" ): cubecolor= ( cubecolor[0], cubecolor[1], cubecolor[2]+0.1 ) cube.color = cubecolor # if "a" is pressed, turn off/on annoying autoscaling if ( s == "a" ): if (scene.autoscale): scene.autoscale = 0 else : scene.autoscale = 1 # "z" goes forward, "x" pulls back if ( s == "z" ): scene.range = scene.range * 0.99 if ( s == "x" ): scene.range = scene.range * 1.01