<s> """<STR_LIT>""" <EOL> from vispy import app , scene , color <EOL> import numpy as np <EOL> npts = <NUM_LIT> <EOL> nedges = <NUM_LIT> <EOL> ngroups = <NUM_LIT:7> <EOL> np . random . seed ( <NUM_LIT> ) <EOL> pos = np . empty ( ( npts , <NUM_LIT:2> ) , dtype = '<STR_LIT>' ) <EOL> colors = np . empty ( ( npts , <NUM_LIT:3> ) , dtype = '<STR_LIT>' ) <EOL> edges = np . empty ( ( nedges , <NUM_LIT:2> ) , dtype = '<STR_LIT>' ) <EOL> types = np . empty ( npts , dtype = int ) <EOL> pos [ : ] = np . random . normal ( size = pos . shape , scale = <NUM_LIT> ) <EOL> grpsize = npts // ngroups <EOL> ptr = <NUM_LIT:0> <EOL> typ = <NUM_LIT:0> <EOL> while ptr < npts : <EOL> size = np . random . random ( ) * grpsize + grpsize // <NUM_LIT:2> <EOL> types [ ptr : ptr + size ] = typ <EOL> typ += <NUM_LIT:1> <EOL> ptr = ptr + size <EOL> conn = [ ] <EOL> connset = set ( ) <EOL> while len ( conn ) < nedges : <EOL> i , j = np . random . randint ( npts , size = <NUM_LIT:2> ) <EOL> if i == j : <EOL> continue <EOL> p = <NUM_LIT> if types [ i ] == types [ j ] else <NUM_LIT> <EOL> if np . random . random ( ) < p : <EOL> if ( i , j ) in connset : <EOL> continue <EOL> connset . add ( ( i , j ) ) <EOL> connset . add ( ( j , i ) ) <EOL> conn . append ( [ i , j ] ) <EOL> edges [ : ] = conn <EOL> cmap = color . get_colormap ( '<STR_LIT>' ) <EOL> typ_colors = np . array ( [ cmap . map ( x ) [ <NUM_LIT:0> , : <NUM_LIT:3> ] for x in np . linspace ( <NUM_LIT> , <NUM_LIT> , typ ) ] ) <EOL> colors [ : ] = typ_colors [ types ] <EOL> colors *= <NUM_LIT> ** np . random . normal ( size = colors . shape ) <EOL> colors = np . clip ( colors , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> canvas = scene . SceneCanvas ( keys = '<STR_LIT>' , show = True ) <EOL> view = canvas . central_widget . add_view ( ) <EOL> view . camera = '<STR_LIT>' <EOL> view . camera . aspect = <NUM_LIT:1> <EOL> lines = scene . Line ( pos = pos , connect = edges , antialias = False , method = '<STR_LIT>' , <EOL> color = ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> ) , parent = view . scene ) <EOL> markers = scene . Markers ( pos = pos , face_color = colors , symbol = '<STR_LIT:o>' , <EOL> parent = view . scene ) <EOL> view . camera . set_range ( ) <EOL> i = <NUM_LIT:1> <EOL> def update ( ev ) : <EOL> global pos , edges , lines , markers , view , force , dist , i <EOL> dx = np . empty ( ( npts , npts , <NUM_LIT:2> ) , dtype = '<STR_LIT>' ) <EOL> dx [ : ] = pos [ : , np . newaxis , : ] <EOL> dx -= pos [ np . newaxis , : , : ] <EOL> dist = ( dx ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:2> ) ** <NUM_LIT:0.5> <EOL> dist [ dist == <NUM_LIT:0> ] = <NUM_LIT:1.> <EOL> ndx = dx / dist [ ... , np . newaxis ] <EOL> force = np . zeros ( ( npts , npts , <NUM_LIT:2> ) , dtype = '<STR_LIT>' ) <EOL> force -= <NUM_LIT:0.1> * ndx / dist [ ... , np . newaxis ] ** <NUM_LIT:2> <EOL> s = <NUM_LIT:0.1> <EOL> mask = np . zeros ( ( npts , npts , <NUM_LIT:1> ) , dtype = '<STR_LIT>' ) <EOL> mask [ edges [ : , <NUM_LIT:0> ] , edges [ : , <NUM_LIT:1> ] ] = s <EOL> mask [ edges [ : , <NUM_LIT:1> ] , edges [ : , <NUM_LIT:0> ] ] = s <EOL> force += dx * dist [ ... , np . newaxis ] * mask <EOL> force [ np . arange ( npts ) , np . arange ( npts ) ] = <NUM_LIT:0> <EOL> force = force . sum ( axis = <NUM_LIT:0> ) <EOL> pos += np . clip ( force , - <NUM_LIT:3> , <NUM_LIT:3> ) * <NUM_LIT> <EOL> lines . set_data ( pos = pos ) <EOL> markers . set_data ( pos = pos , face_color = colors ) <EOL> i += <NUM_LIT:1> <EOL> timer = app . Timer ( interval = <NUM_LIT:0> , connect = update , start = True ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
