<s> """<STR_LIT>""" <EOL> from contextlib import contextmanager <EOL> from OpenGL . GL import * <EOL> @ contextmanager <EOL> def glSection ( type ) : <EOL> glBegin ( type ) <EOL> yield <EOL> glEnd ( ) <EOL> @ contextmanager <EOL> def glMatrix ( ) : <EOL> glPushMatrix ( ) <EOL> yield <EOL> glPopMatrix ( ) <EOL> @ contextmanager <EOL> def glModeMatrix ( type ) : <EOL> glMatrixMode ( type ) <EOL> glPushMatrix ( ) <EOL> yield <EOL> glMatrixMode ( type ) <EOL> glPopMatrix ( ) <EOL> @ contextmanager <EOL> def attributes ( * glBits ) : <EOL> for bit in glBits : <EOL> glPushAttrib ( bit ) <EOL> yield <EOL> for bit in glBits : <EOL> glPopAttrib ( ) <EOL> @ contextmanager <EOL> def enabled ( * glBits ) : <EOL> for bit in glBits : <EOL> glEnable ( bit ) <EOL> yield <EOL> for bit in glBits : <EOL> glDisable ( bit ) <EOL> @ contextmanager <EOL> def disabled ( * glBits ) : <EOL> for bit in glBits : <EOL> glDisable ( bit ) <EOL> yield <EOL> for bit in glBits : <EOL> glEnable ( bit ) <EOL> @ contextmanager <EOL> def overlays2D ( width , height , background_color ) : <EOL> """<STR_LIT>""" <EOL> glDisable ( GL_LIGHTING ) <EOL> glDisable ( GL_LIGHT0 ) <EOL> glDisable ( GL_BLEND ) <EOL> glEnable ( GL_SCISSOR_TEST ) <EOL> with glModeMatrix ( GL_PROJECTION ) : <EOL> yield <EOL> glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> glDisable ( GL_SCISSOR_TEST ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> glLoadIdentity ( ) <EOL> glEnable ( GL_LIGHTING ) <EOL> glEnable ( GL_LIGHT0 ) <EOL> glEnable ( GL_BLEND ) <EOL> glClearColor ( * background_color ) <EOL> def setup_overlay2D ( x , y , width , height ) : <EOL> """<STR_LIT>""" <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> glLoadIdentity ( ) <EOL> glScissor ( x , y , width , height ) <EOL> glViewport ( x , y , width , height ) <EOL> glOrtho ( x , x + width , y , y + height , - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> cyltrigs = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ; <EOL> def notGlePolyCylinder ( points , color , radius ) : <EOL> trigs = [ radius * x for x in cyltrigs ] ; <EOL> if abs ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] - points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] ) > <NUM_LIT> : <EOL> with glSection ( GL_QUAD_STRIP ) : <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.> ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , <NUM_LIT:0> , radius ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , <NUM_LIT:0> , radius ) <EOL> glNormal3f ( <NUM_LIT:0> , cyltrigs [ <NUM_LIT:0> ] , cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , cyltrigs [ <NUM_LIT:2> ] , cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , cyltrigs [ <NUM_LIT:2> ] , - cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , cyltrigs [ <NUM_LIT:0> ] , - cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1.> ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , <NUM_LIT:0> , - radius ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , <NUM_LIT:0> , - radius ) <EOL> glNormal3f ( <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:0> ] , - cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:2> ] , - cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:2> ] , cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:0> ] , cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.> ) <EOL> glVertex ( points [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , <NUM_LIT:0> , radius ) <EOL> glVertex ( points [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] , <NUM_LIT:0> , radius ) <EOL> elif abs ( points [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] - points [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] ) > <NUM_LIT> : <EOL> p1 = points [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> p2 = points [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] <EOL> with glSection ( GL_QUAD_STRIP ) : <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.> ) <EOL> glVertex ( <NUM_LIT:0> , p1 , radius ) <EOL> glVertex ( <NUM_LIT:0> , p2 , radius ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:0> ] , <NUM_LIT:0> , cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , p1 , trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , p2 , trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:2> ] , <NUM_LIT:0> , cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , p1 , trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , p2 , trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:2> ] , <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , p1 , - trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , p2 , - trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:0> ] , <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , p1 , - trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , p2 , - trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1.> ) <EOL> glVertex ( <NUM_LIT:0> , p1 , - radius ) <EOL> glVertex ( <NUM_LIT:0> , p2 , - radius ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:0> ] , <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , p1 , - trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , p2 , - trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:2> ] , <NUM_LIT:0> , - cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , p1 , - trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , p2 , - trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:2> ] , <NUM_LIT:0> , cyltrigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , p1 , trigs [ <NUM_LIT:3> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , p2 , trigs [ <NUM_LIT:3> ] ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:0> ] , <NUM_LIT:0> , cyltrigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , p1 , trigs [ <NUM_LIT:1> ] ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , p2 , trigs [ <NUM_LIT:1> ] ) <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.> ) <EOL> glVertex ( <NUM_LIT:0> , p1 , radius ) <EOL> glVertex ( <NUM_LIT:0> , p2 , radius ) <EOL> else : <EOL> p1 = points [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> p2 = points [ <NUM_LIT:2> ] [ <NUM_LIT:2> ] <EOL> with glSection ( GL_QUAD_STRIP ) : <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:1.> , <NUM_LIT:0> ) <EOL> glVertex ( <NUM_LIT:0> , radius , p1 ) <EOL> glVertex ( <NUM_LIT:0> , radius , p2 ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:0> ] , cyltrigs [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] , p1 ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] , p2 ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:2> ] , cyltrigs [ <NUM_LIT:3> ] , <NUM_LIT:0> ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] , p1 ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] , p2 ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:2> ] , - cyltrigs [ <NUM_LIT:3> ] , <NUM_LIT:0> ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] , p1 ) <EOL> glVertex ( trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] , p2 ) <EOL> glNormal3f ( cyltrigs [ <NUM_LIT:0> ] , - cyltrigs [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] , p1 ) <EOL> glVertex ( trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] , p2 ) <EOL> glNormal3f ( <NUM_LIT:0> , - <NUM_LIT:1.> , <NUM_LIT:0> ) <EOL> glVertex ( <NUM_LIT:0> , - radius , p1 ) <EOL> glVertex ( <NUM_LIT:0> , - radius , p2 ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:0> ] , - cyltrigs [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] , p1 ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , - trigs [ <NUM_LIT:1> ] , p2 ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:2> ] , - cyltrigs [ <NUM_LIT:3> ] , <NUM_LIT:0> ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] , p1 ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , - trigs [ <NUM_LIT:3> ] , p2 ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:2> ] , cyltrigs [ <NUM_LIT:3> ] , <NUM_LIT:0> ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] , p1 ) <EOL> glVertex ( - trigs [ <NUM_LIT:2> ] , trigs [ <NUM_LIT:3> ] , p2 ) <EOL> glNormal3f ( - cyltrigs [ <NUM_LIT:0> ] , cyltrigs [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] , p1 ) <EOL> glVertex ( - trigs [ <NUM_LIT:0> ] , trigs [ <NUM_LIT:1> ] , p2 ) <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:1.> , <NUM_LIT:0> ) <EOL> glVertex ( <NUM_LIT:0> , radius , p1 ) <EOL> glVertex ( <NUM_LIT:0> , radius , p2 ) <EOL> def notGlutSolidCube ( size ) : <EOL> p = size / <NUM_LIT:2> <EOL> n = - <NUM_LIT:1> * p <EOL> with glSection ( GL_QUADS ) : <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.> ) <EOL> glVertex ( n , p , n ) <EOL> glVertex ( n , n , n ) <EOL> glVertex ( p , n , n ) <EOL> glVertex ( p , p , n ) <EOL> with glSection ( GL_QUADS ) : <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:1.> , <NUM_LIT:0> ) <EOL> glVertex ( n , p , p ) <EOL> glVertex ( n , p , n ) <EOL> glVertex ( p , p , n ) <EOL> glVertex ( p , p , p ) <EOL> with glSection ( GL_QUADS ) : <EOL> glNormal3f ( <NUM_LIT:1.> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> glVertex ( p , p , n ) <EOL> glVertex ( p , n , n ) <EOL> glVertex ( p , n , p ) <EOL> glVertex ( p , p , p ) <EOL> with glSection ( GL_QUADS ) : <EOL> glNormal3f ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1.> ) <EOL> glVertex ( p , p , p ) <EOL> glVertex ( p , n , p ) <EOL> glVertex ( n , n , p ) <EOL> glVertex ( n , p , p ) <EOL> with glSection ( GL_QUADS ) : <EOL> glNormal3f ( <NUM_LIT:0> , - <NUM_LIT:1.> , <NUM_LIT:0> ) <EOL> glVertex ( p , n , p ) <EOL> glVertex ( p , n , n ) <EOL> glVertex ( n , n , n ) <EOL> glVertex ( n , n , p ) <EOL> with glSection ( GL_QUADS ) : <EOL> glNormal3f ( - <NUM_LIT:1.> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> glVertex ( n , p , p ) <EOL> glVertex ( n , n , p ) <EOL> glVertex ( n , n , n ) <EOL> glVertex ( n , p , n ) <EOL> class DisplayList ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , renderFunction ) : <EOL> self . renderFunction = renderFunction <EOL> self . needsUpdate = True <EOL> self . listId = None <EOL> def update ( self ) : <EOL> self . needsUpdate = True <EOL> def __call__ ( self , * args ) : <EOL> if self . needsUpdate : <EOL> if self . listId : <EOL> glDeleteLists ( self . listId , <NUM_LIT:1> ) <EOL> self . listId = glGenLists ( <NUM_LIT:1> ) <EOL> glNewList ( self . listId , GL_COMPILE_AND_EXECUTE ) <EOL> self . renderFunction ( * args ) <EOL> glEndList ( ) <EOL> self . needsUpdate = False <EOL> else : <EOL> glCallList ( self . listId ) </s>
