<s> from __future__ import division <EOL> import numpy as np <EOL> from vispy import app <EOL> from vispy . gloo import VertexBuffer <EOL> from vispy . visuals import Visual <EOL> from vispy . visuals . transforms import STTransform <EOL> class MarkerVisual ( Visual ) : <EOL> VERTEX_SHADER = """<STR_LIT>""" <EOL> FRAGMENT_SHADER = """<STR_LIT>""" <EOL> def __init__ ( self , pos = None , color = None , size = None ) : <EOL> Visual . __init__ ( self , self . VERTEX_SHADER , self . FRAGMENT_SHADER ) <EOL> self . _pos = pos <EOL> self . _color = color <EOL> self . _size = size <EOL> self . set_gl_state ( blend = True , <EOL> blend_func = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . _draw_mode = '<STR_LIT>' <EOL> def _prepare_transforms ( self , view = None ) : <EOL> view . view_program . vert [ '<STR_LIT>' ] = view . transforms . get_transform ( ) <EOL> def _prepare_draw ( self , view ) : <EOL> self . shared_program [ '<STR_LIT>' ] = VertexBuffer ( self . _pos ) <EOL> self . shared_program [ '<STR_LIT>' ] = VertexBuffer ( self . _color ) <EOL> self . shared_program [ '<STR_LIT>' ] = VertexBuffer ( self . _size ) <EOL> class Canvas ( app . Canvas ) : <EOL> def __init__ ( self ) : <EOL> app . Canvas . __init__ ( self , keys = '<STR_LIT>' ) <EOL> ps = self . pixel_scale <EOL> n = <NUM_LIT> <EOL> pos = <NUM_LIT> * np . random . randn ( n , <NUM_LIT:2> ) . astype ( np . float32 ) <EOL> color = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:1> , ( n , <NUM_LIT:3> ) ) . astype ( np . float32 ) <EOL> size = np . random . uniform ( <NUM_LIT:2> * ps , <NUM_LIT:12> * ps , ( n , <NUM_LIT:1> ) ) . astype ( np . float32 ) <EOL> self . points = MarkerVisual ( pos = pos , color = color , size = size ) <EOL> w , h = self . size <EOL> self . points . transform = STTransform ( scale = ( w / <NUM_LIT> , h / <NUM_LIT> ) , <EOL> translate = ( w / <NUM_LIT> , h / <NUM_LIT> ) ) <EOL> def on_mouse_move ( self , event ) : <EOL> if event . is_dragging : <EOL> dxy = event . pos - event . last_event . pos <EOL> button = event . press_event . button <EOL> if button == <NUM_LIT:1> : <EOL> self . points . transform . move ( dxy ) <EOL> elif button == <NUM_LIT:2> : <EOL> center = event . press_event . pos <EOL> self . points . transform . zoom ( np . exp ( dxy * ( <NUM_LIT> , - <NUM_LIT> ) ) , center ) <EOL> self . update ( ) <EOL> def on_resize ( self , event ) : <EOL> vp = ( <NUM_LIT:0> , <NUM_LIT:0> , self . physical_size [ <NUM_LIT:0> ] , self . physical_size [ <NUM_LIT:1> ] ) <EOL> self . context . set_viewport ( * vp ) <EOL> self . points . transforms . configure ( canvas = self , viewport = vp ) <EOL> def on_draw ( self , event ) : <EOL> self . context . clear ( '<STR_LIT>' ) <EOL> self . points . draw ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> c = Canvas ( ) <EOL> c . show ( ) <EOL> app . run ( ) </s>
