Modify fig24_01.py so that it allows users to start rotation, stop rotation and change the rotation direction.
What will be an ideal response?
```
# Colored, rotating box (with open top and bottom).
from Tkinter import *
from OpenGL.GL import *
from OpenGL.Tk import *
import Pmw
import sys
class ColorBox( Frame ):
"""A colored, rotating box"""
def __init__( self ):
"""Initialize GUI and OpenGL"""
Frame.__init__( self )
Pmw.initialise()
self.master.title( "Color Box" )
self.master.geometry( "300x300" )
self.pack( expand = YES, fill = BOTH )
# create stop, start and change direction buttons
self.buttonBox = Pmw.ButtonBox( self, labelpos = "n",
frame_borderwidth = 2, frame_relief = "groove" )
self.buttonBox.pack( padx = 10, pady = 10 )
self.buttonBox.add( "Start", command = self.start )
self.buttonBox.add( "Change Rotation Direction",
command = self.changeDirection )
self.buttonBox.add( "Stop", command = self.stop )
# 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.increment = 2 # rotate amount
self.stoped = 1 # rotate status
def redraw( self, openGL ):
"""Draw box 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 )
# constants
red = ( 1.0, 0.0, 0.0 )
green = ( 0.0, 1.0, 0.0 )
blue = ( 0.0, 0.0, 1.0 )
purple = ( 1.0, 0.0, 1.0 )
vertices = \
[ ( ( -3.0, 3.0, -3.0 ), red ),
( ( -3.0, -3.0, -3.0 ), green ),
( ( 3.0, 3.0, -3.0 ), blue ),
( ( 3.0, -3.0, -3.0 ), purple ),
( ( 3.0, 3.0, 3.0 ), red ),
( ( 3.0, -3.0, 3.0 ), green ),
( ( -3.0, 3.0, 3.0 ), blue ),
( ( -3.0, -3.0, 3.0 ), purple ),
( ( -3.0, 3.0, -3.0 ), red ),
( ( -3.0, -3.0, -3.0 ), green ) ]
glBegin( GL_QUAD_STRIP ) # begin drawing
# change color and plot point for each vertex
for vertex in vertices:
location, color = vertex
apply( glColor3f, color )
apply( glVertex3f, location )
glEnd() # stop drawing
glEnable( GL_LIGHTING ) # re-enable lighting
def update( self ):
"""Rotate box"""
if self.stop > 0:
# rotate box around ( 1.0, 1.0, 1.0 )
glRotate( self.increment, 1.0, 1.0, 1.0 )
self.openGL.tkRedraw() # redraw geometry
self.openGL.after( 10, self.update ) # update in 10ms
def start( self ):
"""Start rotating"""
self.stop = 1
self.increment = 2
self.update()
def stop( self ):
"""Stop rotating"""
self.stop = 0
def changeDirection ( self ):
"""Change rotation direction"""
# check current direction and make corresponding changes
if self.increment == 2:
self.increment = -2
else:
self.increment = 2
self.update()
def main():
ColorBox().mainloop()
if __name__ == "__main__":
main()
```

You might also like to view...
________________ is used to redirect all traffic on a switch to a particular port.
a. port mirroring b. proxy serving c. port authentication
What is the motivation behind caching?
What will be an ideal response?
Assume proper includes have been executed, but not using directive or declaration. Write a definition of an iterator for a vector named vec of int values. Write a for loop that will display the contents vec on the screen, separated by spaces. Use iterators for the loop control.
What will be an ideal response?
These devices sometime use ranging to determine the time it takes for data to travel to the cable head-end.
What will be an ideal response?