<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from vispy import app , gloo , visuals <EOL> from vispy . geometry import create_sphere <EOL> from vispy . visuals . transforms import ( STTransform , MatrixTransform , <EOL> ChainTransform ) <EOL> class Canvas ( app . Canvas ) : <EOL> def __init__ ( self ) : <EOL> app . Canvas . __init__ ( self , keys = '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . meshes = [ ] <EOL> self . rotation = MatrixTransform ( ) <EOL> global mdata <EOL> mdata = create_sphere ( <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> self . meshes . append ( visuals . MeshVisual ( meshdata = mdata , color = '<STR_LIT:b>' ) ) <EOL> verts = mdata . get_vertices ( indexed = '<STR_LIT>' ) <EOL> nf = verts . size // <NUM_LIT:9> <EOL> fcolor = np . ones ( ( nf , <NUM_LIT:3> , <NUM_LIT:4> ) , dtype = np . float32 ) <EOL> fcolor [ ... , <NUM_LIT:0> ] = np . linspace ( <NUM_LIT:1> , <NUM_LIT:0> , nf ) [ : , np . newaxis ] <EOL> fcolor [ ... , <NUM_LIT:1> ] = np . random . normal ( size = nf ) [ : , np . newaxis ] <EOL> fcolor [ ... , <NUM_LIT:2> ] = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , nf ) [ : , np . newaxis ] <EOL> mesh = visuals . MeshVisual ( vertices = verts , face_colors = fcolor ) <EOL> self . meshes . append ( mesh ) <EOL> verts = mdata . get_vertices ( ) <EOL> faces = mdata . get_faces ( ) <EOL> nv = verts . size // <NUM_LIT:3> <EOL> vcolor = np . ones ( ( nv , <NUM_LIT:4> ) , dtype = np . float32 ) <EOL> vcolor [ : , <NUM_LIT:0> ] = np . linspace ( <NUM_LIT:1> , <NUM_LIT:0> , nv ) <EOL> vcolor [ : , <NUM_LIT:1> ] = np . random . normal ( size = nv ) <EOL> vcolor [ : , <NUM_LIT:2> ] = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , nv ) <EOL> self . meshes . append ( visuals . MeshVisual ( verts , faces , vcolor ) ) <EOL> self . meshes . append ( visuals . MeshVisual ( verts , faces , vcolor , <EOL> shading = '<STR_LIT>' ) ) <EOL> self . meshes . append ( visuals . MeshVisual ( verts , faces , vcolor , <EOL> shading = '<STR_LIT>' ) ) <EOL> grid = ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> s = <NUM_LIT> / max ( grid ) <EOL> for i , mesh in enumerate ( self . meshes ) : <EOL> x = <NUM_LIT> * ( i % grid [ <NUM_LIT:0> ] ) / grid [ <NUM_LIT:0> ] + <NUM_LIT> / grid [ <NUM_LIT:0> ] - <NUM_LIT:2> <EOL> y = <NUM_LIT> * ( i // grid [ <NUM_LIT:1> ] ) / grid [ <NUM_LIT:1> ] + <NUM_LIT> / grid [ <NUM_LIT:1> ] + <NUM_LIT:2> <EOL> transform = ChainTransform ( [ STTransform ( translate = ( x , y ) , <EOL> scale = ( s , s , s ) ) , <EOL> self . rotation ] ) <EOL> mesh . transform = transform <EOL> mesh . transforms . scene_transform = STTransform ( scale = ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> self . show ( ) <EOL> self . timer = app . Timer ( connect = self . rotate ) <EOL> self . timer . start ( <NUM_LIT> ) <EOL> def rotate ( self , event ) : <EOL> self . rotation . rotate ( <NUM_LIT> ** <NUM_LIT:0.5> , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . rotation . rotate ( <NUM_LIT> ** <NUM_LIT:0.5> , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . rotation . rotate ( <NUM_LIT:0.5> ** <NUM_LIT:0.5> , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) <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> for mesh in self . meshes : <EOL> mesh . transforms . configure ( canvas = self , viewport = vp ) <EOL> def on_draw ( self , ev ) : <EOL> gloo . set_viewport ( <NUM_LIT:0> , <NUM_LIT:0> , * self . physical_size ) <EOL> gloo . clear ( color = '<STR_LIT>' , depth = True ) <EOL> for mesh in self . meshes : <EOL> mesh . draw ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> win = Canvas ( ) <EOL> import sys <EOL> if sys . flags . interactive != <NUM_LIT:1> : <EOL> app . run ( ) </s>
