Modify fig24_02.py to make the shape spin.

What will be an ideal response?


```
# Demonstrating various GLUT shapes.

from Tkinter import *
import Pmw
from OpenGL.GL import *
from OpenGL.Tk import *
from OpenGL.GLUT import *

class ChooseShape( Frame ):
"""Allow user to preview different shapes and colors"""

def __init__( self ):
"""Initialize GUI and OpenGL"""

Frame.__init__( self )
Pmw.initialise()
self.master.title( "Choose a shape and color" )
self.master.geometry( "300x300" )
self.pack( expand = YES, fill = BOTH )

# create and pack MenuBar
self.choices = Pmw.MenuBar( self )
self.choices.pack( fill = X )

# create and pack Opengl -- use double buffering
self.openGL = Opengl( self, double = 1 )
self.openGL.pack( expand = YES, fill = BOTH )

self.openGL.redraw = self.redraw # set redraw function
self.openGL.set_eyepoint( 20 ) # move away from object
self.openGL.autospin_allowed = 1 # allow auto-spin

self.choices.addmenu( "Shape", None ) # Shape submenu

# possible shapes and arguments
self.shapes = { "glutWireCube" : ( 3, ),
"glutSolidCube": ( 3, ),
"glutWireIcosahedron" : (),
"glutSolidIcosahedron" : (),
"glutWireCone" : ( 3, 3, 50, 50 ),
"glutSolidCone" : ( 3, 3, 50, 50 ),
"glutWireTorus" : ( 1, 3, 50, 50 ),
"glutSolidTorus" : ( 1, 3, 50, 50 ),
"glutWireTeapot" : ( 3, ),
"glutSolidTeapot" : ( 3, ) }

self.selectedShape = StringVar()
self.selectedShape.set( "glutWireCube" )

sortedShapes = self.shapes.keys()
sortedShapes.sort() # sort names before adding to menu

# add items to Shape menu
for shape in sortedShapes:
self.choices.addmenuitem( "Shape", "radiobutton",
label = shape, variable = self.selectedShape,
command = self.refresh )

self.choices.addmenu( "Color", None ) # Color submenu

# possible colors and their values
self.colors = { "White" : ( 1.0, 1.0, 1.0 ),
"Blue" : ( 0.0, 0.0, 1.0 ),
"Red" : ( 1.0, 0.0, 0.0 ),
"Green" : ( 0.0, 1.0, 0.0 ),
"Magenta" : ( 1.0, 0.0, 1.0 ) }

self.selectedColor = StringVar()
self.selectedColor.set( "White" )

# add items to Color menu
for color in self.colors.keys():
self.choices.addmenuitem( "Color", "radiobutton",
label = color, variable = self.selectedColor,
command = self.refresh )

def redraw( self, openGL ):
"""Draw selected shape on black background"""

# clear background and disable lighting
glClearColor( 0.0, 0.0, 0.0, 0.0 ) # select clear color
glClear( GL_COLOR_BUFFER_BIT ) # paint background
glDisable( GL_LIGHTING )

# obtain and set selected color
color = self.selectedColor.get()
apply( glColor3f, self.colors[ color ] )

# obtain and draw selected shape
shape = self.selectedShape.get()
apply( eval( shape ), self.shapes[ shape ] )

def refresh( self ):
"""Refresh window"""

# reset window title to corresponding shape and color
self.master.title( self.selectedShape.get() + " " \
+ self.selectedColor.get() )

# allow autospin
self.openGL.autospin = 1

# set spin position
self.openGL.xspin = 150
self.openGL.yspin = 150

# call autospin in 100ms
self.openGL.after( 100, self.openGL.do_AutoSpin )

def main():
ChooseShape().mainloop()

if __name__ == "__main__":
main()
```
![15197|205x210](upload://m41lRQ2NsircYgxvn2F5nLrHz4L.png)

Computer Science & Information Technology

You might also like to view...

Java provides ____ different loop statements, each with its own use.

A. two B. three C. four D. five

Computer Science & Information Technology

If no memory is available, keyword new throws an __________.

a. OutOfMemoryException. b. OutOfMemoryEvent. c. OutOfMemoryExhaustion. d. OutOfMemoryError.

Computer Science & Information Technology

What contains file and directory metadata and provides a mechanism for linking data stored in data blocks?

a. Xnodes b. Extnodes c. InfNodes d. Inodes

Computer Science & Information Technology

The Scene panel can be displayed by pointing to ____ on the Window menu and then clicking Scene.

A. Options B. Other Panels C. Panels D. Views

Computer Science & Information Technology