<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from vispy import app , gloo <EOL> from vispy . io import read_mesh , load_data_file , load_crate <EOL> from vispy . util . transforms import perspective , translate , rotate <EOL> try : <EOL> app_object = app . use_app ( '<STR_LIT>' ) <EOL> except Exception : <EOL> app_object = app . use_app ( '<STR_LIT>' ) <EOL> QtCore = app_object . backend_module . QtCore , <EOL> QtGui = app_object . backend_module . QtGui <EOL> VERT_CODE = """<STR_LIT>""" <EOL> FRAG_CODE = """<STR_LIT>""" <EOL> positions , faces , normals , texcoords = read_mesh ( load_data_file ( '<STR_LIT>' ) ) <EOL> colors = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:1> , positions . shape ) . astype ( '<STR_LIT>' ) <EOL> faces_buffer = gloo . IndexBuffer ( faces . astype ( np . uint16 ) ) <EOL> class Canvas ( app . Canvas ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> app . Canvas . __init__ ( self , size = ( <NUM_LIT> , <NUM_LIT> ) , ** kwargs ) <EOL> self . program = gloo . Program ( VERT_CODE , FRAG_CODE ) <EOL> self . program [ '<STR_LIT>' ] = gloo . VertexBuffer ( positions ) <EOL> self . program [ '<STR_LIT>' ] = gloo . VertexBuffer ( texcoords ) <EOL> self . program [ '<STR_LIT>' ] = gloo . Texture2D ( load_crate ( ) ) <EOL> self . init_transforms ( ) <EOL> self . apply_zoom ( ) <EOL> gloo . set_clear_color ( ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> gloo . set_state ( depth_test = True ) <EOL> self . _timer = app . Timer ( '<STR_LIT>' , connect = self . update_transforms ) <EOL> self . _timer . start ( ) <EOL> self . show ( ) <EOL> def on_resize ( self , event ) : <EOL> self . apply_zoom ( ) <EOL> def on_draw ( self , event ) : <EOL> gloo . clear ( ) <EOL> self . program . draw ( '<STR_LIT>' , faces_buffer ) <EOL> def init_transforms ( self ) : <EOL> self . theta = <NUM_LIT:0> <EOL> self . phi = <NUM_LIT:0> <EOL> self . view = translate ( ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:5> ) ) <EOL> self . model = np . eye ( <NUM_LIT:4> , dtype = np . float32 ) <EOL> self . projection = np . eye ( <NUM_LIT:4> , dtype = np . float32 ) <EOL> self . program [ '<STR_LIT>' ] = self . model <EOL> self . program [ '<STR_LIT>' ] = self . view <EOL> def update_transforms ( self , event ) : <EOL> self . theta += <NUM_LIT> <EOL> self . phi += <NUM_LIT> <EOL> self . model = np . dot ( rotate ( self . theta , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) , <EOL> rotate ( self . phi , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ) ) <EOL> self . program [ '<STR_LIT>' ] = self . model <EOL> self . update ( ) <EOL> def apply_zoom ( self ) : <EOL> gloo . set_viewport ( <NUM_LIT:0> , <NUM_LIT:0> , self . physical_size [ <NUM_LIT:0> ] , self . physical_size [ <NUM_LIT:1> ] ) <EOL> self . projection = perspective ( <NUM_LIT> , self . size [ <NUM_LIT:0> ] / <EOL> float ( self . size [ <NUM_LIT:1> ] ) , <NUM_LIT> , <NUM_LIT> ) <EOL> self . program [ '<STR_LIT>' ] = self . projection <EOL> class TextField ( QtGui . QPlainTextEdit ) : <EOL> def __init__ ( self , parent ) : <EOL> QtGui . QPlainTextEdit . __init__ ( self , parent ) <EOL> font = QtGui . QFont ( '<STR_LIT>' ) <EOL> font . setStyleHint ( font . TypeWriter , font . PreferDefault ) <EOL> font . setPointSize ( <NUM_LIT:8> ) <EOL> self . setFont ( font ) <EOL> class MainWindow ( QtGui . QWidget ) : <EOL> def __init__ ( self ) : <EOL> QtGui . QWidget . __init__ ( self , None ) <EOL> self . setMinimumSize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . vertLabel = QtGui . QLabel ( "<STR_LIT>" , self ) <EOL> self . fragLabel = QtGui . QLabel ( "<STR_LIT>" , self ) <EOL> self . theButton = QtGui . QPushButton ( "<STR_LIT>" , self ) <EOL> self . theButton . clicked . connect ( self . on_compile ) <EOL> self . vertEdit = TextField ( self ) <EOL> self . vertEdit . setPlainText ( VERT_CODE ) <EOL> self . fragEdit = TextField ( self ) <EOL> self . fragEdit . setPlainText ( FRAG_CODE ) <EOL> self . canvas = Canvas ( parent = self ) <EOL> hlayout = QtGui . QHBoxLayout ( self ) <EOL> self . setLayout ( hlayout ) <EOL> vlayout = QtGui . QVBoxLayout ( ) <EOL> hlayout . addLayout ( vlayout , <NUM_LIT:1> ) <EOL> hlayout . addWidget ( self . canvas . native , <NUM_LIT:1> ) <EOL> vlayout . addWidget ( self . vertLabel , <NUM_LIT:0> ) <EOL> vlayout . addWidget ( self . vertEdit , <NUM_LIT:1> ) <EOL> vlayout . addWidget ( self . fragLabel , <NUM_LIT:0> ) <EOL> vlayout . addWidget ( self . fragEdit , <NUM_LIT:1> ) <EOL> vlayout . addWidget ( self . theButton , <NUM_LIT:0> ) <EOL> self . show ( ) <EOL> def on_compile ( self ) : <EOL> vert_code = str ( self . vertEdit . toPlainText ( ) ) <EOL> frag_code = str ( self . fragEdit . toPlainText ( ) ) <EOL> self . canvas . program . set_shaders ( vert_code , frag_code ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . create ( ) <EOL> m = MainWindow ( ) <EOL> app . run ( ) </s>
