<s> import numpy as np <EOL> from . visual import Visual <EOL> from . . import gloo <EOL> class ScrollingLinesVisual ( Visual ) : <EOL> """<STR_LIT>""" <EOL> vertex_code = """<STR_LIT>""" <EOL> fragment_code = """<STR_LIT>""" <EOL> def __init__ ( self , n_lines , line_size , dx , color = None , pos_offset = None , <EOL> columns = None , cell_size = None ) : <EOL> self . _pos_data = None <EOL> self . _offset = <NUM_LIT:0> <EOL> self . _dx = dx <EOL> data = np . zeros ( ( n_lines , line_size ) , dtype = '<STR_LIT>' ) <EOL> self . _pos_tex = gloo . Texture2D ( data , format = '<STR_LIT>' , <EOL> internalformat = '<STR_LIT>' ) <EOL> self . _index_buf = gloo . VertexBuffer ( ) <EOL> self . _data_shape = data . shape <EOL> Visual . __init__ ( self , vcode = self . vertex_code , fcode = self . fragment_code ) <EOL> self . shared_program [ '<STR_LIT>' ] = self . _pos_tex <EOL> self . shared_program [ '<STR_LIT:index>' ] = self . _index_buf <EOL> self . shared_program [ '<STR_LIT>' ] = dx <EOL> self . shared_program [ '<STR_LIT>' ] = data . shape <EOL> self . shared_program [ '<STR_LIT>' ] = self . _offset <EOL> if pos_offset is None : <EOL> rows = np . ceil ( n_lines / columns ) <EOL> pos_offset = np . empty ( ( rows , columns , <NUM_LIT:3> ) , dtype = '<STR_LIT>' ) <EOL> pos_offset [ ... , <NUM_LIT:0> ] = ( np . arange ( columns ) [ np . newaxis , : ] * <EOL> cell_size [ <NUM_LIT:0> ] ) <EOL> pos_offset [ ... , <NUM_LIT:1> ] = np . arange ( rows ) [ : , np . newaxis ] * cell_size [ <NUM_LIT:1> ] <EOL> pos_offset = pos_offset . reshape ( ( rows * columns ) , <NUM_LIT:3> ) <EOL> self . _pos_offset = gloo . Texture1D ( pos_offset , internalformat = '<STR_LIT>' , <EOL> interpolation = '<STR_LIT>' ) <EOL> self . shared_program [ '<STR_LIT>' ] = self . _pos_offset <EOL> if color is None : <EOL> self . shared_program . frag [ '<STR_LIT>' ] = ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> else : <EOL> self . _color_tex = gloo . Texture1D ( color ) <EOL> self . shared_program [ '<STR_LIT>' ] = self . _color_tex <EOL> self . shared_program . frag [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> index = np . empty ( ( data . shape [ <NUM_LIT:0> ] , data . shape [ <NUM_LIT:1> ] , <NUM_LIT:2> ) , dtype = '<STR_LIT>' ) <EOL> index [ ... , <NUM_LIT:0> ] = np . arange ( data . shape [ <NUM_LIT:0> ] ) [ : , np . newaxis ] <EOL> index [ ... , <NUM_LIT:1> ] = np . arange ( data . shape [ <NUM_LIT:1> ] ) [ np . newaxis , : ] <EOL> index = index . reshape ( ( index . shape [ <NUM_LIT:0> ] * index . shape [ <NUM_LIT:1> ] , index . shape [ <NUM_LIT:2> ] ) ) <EOL> self . _index_buf . set_data ( index ) <EOL> self . _draw_mode = '<STR_LIT>' <EOL> self . set_gl_state ( '<STR_LIT>' , line_width = <NUM_LIT:1> ) <EOL> self . freeze ( ) <EOL> def set_pos_offset ( self , po ) : <EOL> """<STR_LIT>""" <EOL> self . _pos_offset . set_data ( po ) <EOL> def set_color ( self , color ) : <EOL> """<STR_LIT>""" <EOL> self . _color_tex . set_data ( color ) <EOL> def _prepare_transforms ( self , view ) : <EOL> view . view_program . vert [ '<STR_LIT>' ] = view . get_transform ( ) . simplified <EOL> def _prepare_draw ( self , view ) : <EOL> pass <EOL> def _compute_bounds ( self , axis , view ) : <EOL> if self . _pos_data is None : <EOL> return None <EOL> return self . _pos_data [ ... , axis ] . min ( ) , self . pos_data [ ... , axis ] . max ( ) <EOL> def roll_data ( self , data ) : <EOL> """<STR_LIT>""" <EOL> data = data . astype ( '<STR_LIT>' ) [ ... , np . newaxis ] <EOL> s1 = self . _data_shape [ <NUM_LIT:1> ] - self . _offset <EOL> if data . shape [ <NUM_LIT:1> ] > s1 : <EOL> self . _pos_tex [ : , self . _offset : ] = data [ : , : s1 ] <EOL> self . _pos_tex [ : , : data . shape [ <NUM_LIT:1> ] - s1 ] = data [ : , s1 : ] <EOL> self . _offset = ( self . _offset + data . shape [ <NUM_LIT:1> ] ) % self . _data_shape [ <NUM_LIT:1> ] <EOL> else : <EOL> self . _pos_tex [ : , self . _offset : self . _offset + data . shape [ <NUM_LIT:1> ] ] = data <EOL> self . _offset += data . shape [ <NUM_LIT:1> ] <EOL> self . shared_program [ '<STR_LIT>' ] = self . _offset <EOL> self . update ( ) <EOL> def set_data ( self , index , data ) : <EOL> """<STR_LIT>""" <EOL> self . _pos_tex [ index , : ] = data <EOL> self . update ( ) </s>
