<s> """<STR_LIT>""" <EOL> from sympy import symbols <EOL> from sympy . plotting . pygletplot import PygletPlot <EOL> from sympy import sin , cos , pi , sqrt , exp <EOL> from sympy . core . compatibility import range <EOL> from time import sleep , clock <EOL> def main ( ) : <EOL> x , y , z = symbols ( '<STR_LIT>' ) <EOL> axes_options = '<STR_LIT>' <EOL> p = PygletPlot ( <EOL> width = <NUM_LIT> , <EOL> height = <NUM_LIT> , <EOL> ortho = False , <EOL> invert_mouse_zoom = False , <EOL> axes = axes_options , <EOL> antialiasing = True ) <EOL> examples = [ ] <EOL> def example_wrapper ( f ) : <EOL> examples . append ( f ) <EOL> return f <EOL> @ example_wrapper <EOL> def mirrored_saddles ( ) : <EOL> p [ <NUM_LIT:5> ] = x ** <NUM_LIT:2> - y ** <NUM_LIT:2> , [ <NUM_LIT:20> ] , [ <NUM_LIT:20> ] <EOL> p [ <NUM_LIT:6> ] = y ** <NUM_LIT:2> - x ** <NUM_LIT:2> , [ <NUM_LIT:20> ] , [ <NUM_LIT:20> ] <EOL> @ example_wrapper <EOL> def mirrored_saddles_saveimage ( ) : <EOL> p [ <NUM_LIT:5> ] = x ** <NUM_LIT:2> - y ** <NUM_LIT:2> , [ <NUM_LIT:20> ] , [ <NUM_LIT:20> ] <EOL> p [ <NUM_LIT:6> ] = y ** <NUM_LIT:2> - x ** <NUM_LIT:2> , [ <NUM_LIT:20> ] , [ <NUM_LIT:20> ] <EOL> p . wait_for_calculations ( ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> p . saveimage ( "<STR_LIT>" ) <EOL> @ example_wrapper <EOL> def mirrored_ellipsoids ( ) : <EOL> p [ <NUM_LIT:2> ] = x ** <NUM_LIT:2> + y ** <NUM_LIT:2> , [ <NUM_LIT> ] , [ <NUM_LIT> ] , '<STR_LIT>' <EOL> p [ <NUM_LIT:3> ] = - x ** <NUM_LIT:2> - y ** <NUM_LIT:2> , [ <NUM_LIT> ] , [ <NUM_LIT> ] , '<STR_LIT>' <EOL> @ example_wrapper <EOL> def saddle_colored_by_derivative ( ) : <EOL> f = x ** <NUM_LIT:2> - y ** <NUM_LIT:2> <EOL> p [ <NUM_LIT:1> ] = f , '<STR_LIT>' <EOL> p [ <NUM_LIT:1> ] . color = abs ( f . diff ( x ) ) , abs ( f . diff ( x ) + f . diff ( y ) ) , abs ( f . diff ( y ) ) <EOL> @ example_wrapper <EOL> def ding_dong_surface ( ) : <EOL> f = sqrt ( <NUM_LIT:1.0> - y ) * y <EOL> p [ <NUM_LIT:1> ] = f , [ x , <NUM_LIT:0> , <NUM_LIT:2> * pi , <EOL> <NUM_LIT> ] , [ y , - <EOL> <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:100> ] , '<STR_LIT>' <EOL> @ example_wrapper <EOL> def polar_circle ( ) : <EOL> p [ <NUM_LIT:7> ] = <NUM_LIT:1> , '<STR_LIT>' <EOL> @ example_wrapper <EOL> def polar_flower ( ) : <EOL> p [ <NUM_LIT:8> ] = <NUM_LIT> * sin ( <NUM_LIT:4> * x ) , [ <NUM_LIT> ] , '<STR_LIT>' <EOL> p [ <NUM_LIT:8> ] . color = z , x , y , ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0.5> ) , ( <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , ( x , y , None , z ) <EOL> @ example_wrapper <EOL> def simple_cylinder ( ) : <EOL> p [ <NUM_LIT:9> ] = <NUM_LIT:1> , '<STR_LIT>' <EOL> @ example_wrapper <EOL> def cylindrical_hyperbola ( ) : <EOL> p [ <NUM_LIT:10> ] = <NUM_LIT:1> / y , '<STR_LIT>' , [ x ] , [ y , - <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:20> ] <EOL> @ example_wrapper <EOL> def extruded_hyperbolas ( ) : <EOL> p [ <NUM_LIT:11> ] = <NUM_LIT:1> / x , [ x , - <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:100> ] , [ <NUM_LIT:1> ] , '<STR_LIT>' <EOL> p [ <NUM_LIT:12> ] = - <NUM_LIT:1> / x , [ x , - <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:100> ] , [ <NUM_LIT:1> ] , '<STR_LIT>' <EOL> @ example_wrapper <EOL> def torus ( ) : <EOL> a , b = <NUM_LIT:1> , <NUM_LIT:0.5> <EOL> p [ <NUM_LIT> ] = ( a + b * cos ( x ) ) * cos ( y ) , ( a + b * cos ( x ) ) * sin ( y ) , b * sin ( x ) , [ x , <NUM_LIT:0> , pi * <NUM_LIT:2> , <NUM_LIT> ] , [ y , <NUM_LIT:0> , pi * <NUM_LIT:2> , <NUM_LIT> ] <EOL> @ example_wrapper <EOL> def warped_torus ( ) : <EOL> a , b = <NUM_LIT:2> , <NUM_LIT:1> <EOL> p [ <NUM_LIT> ] = ( a + b * cos ( x ) ) * cos ( y ) , ( a + b * cos ( x ) ) * sin ( y ) , b * sin ( x ) + <NUM_LIT:0.5> * sin ( <NUM_LIT:4> * y ) , [ x , <NUM_LIT:0> , pi * <NUM_LIT:2> , <NUM_LIT> ] , [ y , <NUM_LIT:0> , pi * <NUM_LIT:2> , <NUM_LIT> ] <EOL> @ example_wrapper <EOL> def parametric_spiral ( ) : <EOL> p [ <NUM_LIT> ] = cos ( y ) , sin ( y ) , y / <NUM_LIT> , [ y , - <NUM_LIT:4> * pi , <NUM_LIT:4> * pi , <NUM_LIT:100> ] <EOL> p [ <NUM_LIT> ] . color = x , ( <NUM_LIT:0.1> , <NUM_LIT> ) , y , ( <NUM_LIT:0.1> , <NUM_LIT> ) , z , ( <NUM_LIT:0.1> , <NUM_LIT> ) <EOL> @ example_wrapper <EOL> def multistep_gradient ( ) : <EOL> p [ <NUM_LIT:1> ] = <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' <EOL> gradient = [ <NUM_LIT:0.0> , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> ) , <EOL> <NUM_LIT> , ( <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> ) , <EOL> <NUM_LIT> , ( <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> ) , <EOL> <NUM_LIT> , ( <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ) , <EOL> <NUM_LIT> , ( <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ) , <EOL> <NUM_LIT:1.0> , ( <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ) ] <EOL> p [ <NUM_LIT:1> ] . color = z , [ None , None , z ] , gradient <EOL> @ example_wrapper <EOL> def lambda_vs_sympy_evaluation ( ) : <EOL> start = clock ( ) <EOL> p [ <NUM_LIT:4> ] = x ** <NUM_LIT:2> + y ** <NUM_LIT:2> , [ <NUM_LIT:100> ] , [ <NUM_LIT:100> ] , '<STR_LIT>' <EOL> p . wait_for_calculations ( ) <EOL> print ( "<STR_LIT>" % ( clock ( ) - start ) ) <EOL> start = clock ( ) <EOL> p [ <NUM_LIT:4> ] = x ** <NUM_LIT:2> + y ** <NUM_LIT:2> , [ <NUM_LIT:100> ] , [ <NUM_LIT:100> ] , '<STR_LIT>' <EOL> p . wait_for_calculations ( ) <EOL> print ( <EOL> "<STR_LIT>" % <EOL> ( clock ( ) - start ) ) <EOL> @ example_wrapper <EOL> def gradient_vectors ( ) : <EOL> def gradient_vectors_inner ( f , i ) : <EOL> from sympy import lambdify <EOL> from sympy . plotting . plot_interval import PlotInterval <EOL> from pyglet . gl import glBegin , glColor3f <EOL> from pyglet . gl import glVertex3f , glEnd , GL_LINES <EOL> def draw_gradient_vectors ( f , iu , iv ) : <EOL> """<STR_LIT>""" <EOL> dx , dy , dz = f . diff ( x ) , f . diff ( y ) , <NUM_LIT:0> <EOL> FF = lambdify ( [ x , y ] , [ x , y , f ] ) <EOL> FG = lambdify ( [ x , y ] , [ dx , dy , dz ] ) <EOL> iu . v_steps /= <NUM_LIT:5> <EOL> iv . v_steps /= <NUM_LIT:5> <EOL> Gvl = list ( list ( [ FF ( u , v ) , FG ( u , v ) ] <EOL> for v in iv . frange ( ) ) <EOL> for u in iu . frange ( ) ) <EOL> def draw_arrow ( p1 , p2 ) : <EOL> """<STR_LIT>""" <EOL> glColor3f ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> glVertex3f ( * p1 ) <EOL> glColor3f ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> glVertex3f ( * p2 ) <EOL> def draw ( ) : <EOL> """<STR_LIT>""" <EOL> glBegin ( GL_LINES ) <EOL> for u in Gvl : <EOL> for v in u : <EOL> point = [ [ v [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , v [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , v [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ] , <EOL> [ v [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] + v [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , v [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] + v [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , v [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] + v [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] ] ] <EOL> draw_arrow ( point [ <NUM_LIT:0> ] , point [ <NUM_LIT:1> ] ) <EOL> glEnd ( ) <EOL> return draw <EOL> p [ i ] = f , [ - <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT> ] , [ - <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT> ] , '<STR_LIT>' <EOL> iu = PlotInterval ( p [ i ] . intervals [ <NUM_LIT:0> ] ) <EOL> iv = PlotInterval ( p [ i ] . intervals [ <NUM_LIT:1> ] ) <EOL> p [ i ] . postdraw . append ( draw_gradient_vectors ( f , iu , iv ) ) <EOL> gradient_vectors_inner ( x ** <NUM_LIT:2> + y ** <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> gradient_vectors_inner ( - x ** <NUM_LIT:2> - y ** <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> def help_str ( ) : <EOL> s = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> for i in range ( len ( examples ) ) : <EOL> s += "<STR_LIT>" % ( i , examples [ i ] . __name__ ) <EOL> s += "<STR_LIT:\n>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> return s <EOL> def example ( i ) : <EOL> if callable ( i ) : <EOL> p . clear ( ) <EOL> i ( ) <EOL> elif i >= <NUM_LIT:0> and i < len ( examples ) : <EOL> p . clear ( ) <EOL> examples [ i ] ( ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> print ( p ) <EOL> example ( <NUM_LIT:0> ) <EOL> print ( help_str ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
