# Hands On Activities plaintext version of colorfun.py:

 ```""" colorfun.py by Kirby Urner Saturday Academy Summer School """ from visual import * # lots coming into our namespace here phi = (1 + sqrt(5))/2 # golden ratio def setscene ( ): """set the stage for our little drama""" scene2 = display(title='Cycling Through Colors', fullscreen= True, autoscale = False, background=color.white, scale = vector(0.1, 0.1, 0.1)) return scene2 def multicolor( ): """ goes through some color changes, using a selected shape """ answer = raw_input("1. sphere 2. cylinder 3. box 4. helix >> ") if answer not in ["1", "2", "3", "4"]: print "Sorry, don't know what to do..." return else: scene = setscene( ) scene.select( ) if answer == "1": theshape = sphere(pos=(0,0,0), radius = 1) elif answer == "2": theshape = cylinder(pos = (-5,0,0), radius = 0.5, axis = (10, 0, 0)) elif answer == "3": theshape = box(pos = (0,0,0), length = phi, height = 1/phi, width = 1, axis=(1,1,1)) elif answer == "4": theshape = helix(pos=(-2.5,0,0), axis=(5,0,0), radius=0.5) decimals = [ x / 10.0 for x in range(0, 11) ] # [0.0, 0.1, 0.2, 0.3... 1.0] for red in decimals: # cycle through all the colors, using whatever selected shape for green in decimals: for blue in decimals: theshape.color = (red, green, blue) rate(50) print "OK, done..." scene.visible = False return if __name__ == "__main__": multicolor( )```

cut and paste the above code to an open window in your program editor. save and run. PREV | NEXT | TOC | HOME