2 from __future__
import print_function
4 import matplotlib.mlab
as mml
5 import mayavi.mlab
as ml
11 spin(): Spin the view interactively 12 zoom(): Zoom the view a factor exp(e), in n steps 13 dolly(): Dolly the view a factor exp(e), in n steps 14 spin_zoom(): Spin + zoom the view interactively 15 spin_movie(): Spin one turn, saving images in dir 16 cube(): Construct a cube 17 torus(): Construct a torus of cubes 19 Type e.g. spin?<RETURN> for iPython help, or spin( for 20 pop-up help in Canopy. 22 print(
"Type mayavi_utils?<RETURN> for help text, or \ 23 mayavi_utils( for pop-up help in Canopy")
28 Spin the view interactively 32 f.scene.camera.azimuth(1)
36 @ml.animate(delay=10,ui=
None)
37 def zoom(e=1.0,n=200):
39 Zoom the view a factor exp(e), in n steps 44 g.scene.camera.zoom(f)
49 def spin_zoom(factor=2.,n=360,phi=360,name='im',save=0):
51 Spin + zoom the view interactively 57 f.scene.camera.azimuth(dphi)
58 f.scene.camera.zoom(1.0+eps)
61 file=name+
'_{:04d}.png'.format(i)
65 f.scene.camera.azimuth(dphi)
66 f.scene.camera.zoom(1.0-eps)
69 file=name+
'_{:04d}.png'.format(i+n)
73 @ml.animate(delay=10,ui=
None)
74 def dolly(e=1.0,n=200):
76 Dolly the view a factor exp(e), in n steps 81 g.scene.camera.dolly(f)
86 def spin_movie(dir='anim',n=360):
88 Spin the view 360 degrees, in n steps, saving images in dir 90 os.system(
'mkdir -p '+dir)
94 g.scene.camera.azimuth(dphi)
97 file=dir+
'/im_{:03d}.png'.format(i)
102 def cube(x=0,y=0,z=0,size=1,phi=30):
106 c=np.cos(phi+np.pi/4)
107 s=np.sin(phi+np.pi/4)
108 x1=0.5*size*c*np.sqrt(2.)
109 y1=0.5*size*s*np.sqrt(2.)
111 x2=x+np.array([+x1,-y1,-x1,+y1,+x1])
112 y2=y+np.array([+y1,+x1,-y1,-x1,+y1])
113 z2=z+np.array([+z1,+z1,+z1,+z1,+z1])
115 ml.plot3d(x2,y2,+z2,tube_radius=
None,line_width=lw)
116 ml.plot3d(x2,y2,-z2,tube_radius=
None,line_width=lw)
118 ml.plot3d([x2[i],x2[i]],[y2[i],y2[i]],[-z1,z1],tube_radius=
None,line_width=lw)
120 def torus(size=1.,levels=1,nphi=31,n=31,azimuth=90.):
122 Construct a torus consisting of cubes with given size 126 size=2.2*0.9**(1./3.)*3**levels
131 y=radius*(np.sin(phi)-1.0)
135 ml.view(focalpoint=[0.,0.,0.],azimuth=azimuth,elevation=75.,