def test_gui(self): pp = Pointset(3) pp.append(0, 0, 0) pp.append(0, 1, 0) pp.append(1, 2, 0) pp.append(0, 2, 1) # Create all solids vv.solidBox((0, 0, 0)) sphere = vv.solidSphere((3, 0, 0)) cone = vv.solidCone((6, 0, 0)) # a cone with 4 faces is a pyramid pyramid = vv.solidCone((9, 0, 0), N=4) vv.solidCylinder((0, 3, 0), (1, 1, 2)) ring = vv.solidRing((3, 3, 0)) vv.solidTeapot((6, 3, 0)) vv.solidLine(pp+Point(9, 3, 0), radius=0.2) # Make the ring green ring.faceColor = 'g' # Make the sphere dull sphere.specular = 0 sphere.diffuse = 0.4 # Show lines in yellow pyramid pyramid.faceColor = 'r' pyramid.edgeShading = 'plain' # Colormap example N = cone._vertices.shape[0] cone.SetValues(np.linspace(0, 1, N)) cone.colormap = vv.CM_JET
from visvis import Point, Pointset vv.figure() a = vv.gca() # Define points for the line pp = Pointset(3) pp.append(0,0,0); pp.append(0,1,0); pp.append(1,2,0); pp.append(0,2,1) # Create all solids box = vv.solidBox((0,0,0)) sphere = vv.solidSphere((3,0,0)) cone = vv.solidCone((6,0,0)) pyramid = vv.solidCone((9,0,0), N=4) # a cone with 4 faces is a pyramid cylinder = vv.solidCylinder((0,3,0),(1,1,2)) ring = vv.solidRing((3,3,0)) teapot = vv.solidTeapot((6,3,0)) line = vv.solidLine(pp+Point(9,3,0), radius = 0.2) # Let's put a face on that cylinder # This works because 2D texture coordinates are automatically generated for # the sphere, cone, cylinder and ring. im = vv.imread('astronaut.png') cylinder.SetTexture(im) # Make the ring green ring.faceColor = 'g' # Make the sphere dull sphere.specular = 0 sphere.diffuse = 0.4
if axes is None: axes = vv.gca() # Create Mesh object m = vv.OrientableMesh(axes, bm) # if translation is not None: m.translation = translation if scaling is not None: m.scaling = scaling if direction is not None: m.direction = direction if rotation is not None: m.rotation = rotation # Adjust axes if axesAdjust: if axes.daspectAuto is None: axes.daspectAuto = False axes.cameraType = '3d' axes.SetLimits() # Done axes.Draw() return m if __name__ == '__main__': m = vv.solidTeapot(direction=(0.1, 0.2, 1)) m.faceShading = 'toon' # Let's try the 'toon' shader for a change!
Parameters ---------- viewparams : dict View parameters to set. axes : Axes instance The axes the view parameters are for. Uses the current axes by default. keyword pairs View parameters to set. These take precidence. If neither viewparams or any keyword pairs are given, returns the current view parameters (as a dict). Otherwise, sets the view parameters given. """ if axes is None: axes = vv.gca() if viewparams or kw: axes.SetView(viewparams, **kw) else: return axes.GetView() if __name__=='__main__': a = vv.gca() vv.solidTeapot() v = vv.view() # ... rotate the figure a bit and then call: vv.view(v) # Note that a.GetView() and a.SetView(v) are equivalent
#!/usr/bin/env python """ Example that demonstrates how movies can be recorded and exported to gif/swf/avi. This is not an interactive example, but a script. """ import visvis as vv # Create something to show, let's show a red teapot! mesh = vv.solidTeapot() mesh.faceColor = 'r' # Prepare Nangles = 36 a = vv.gca() f = vv.gcf() rec = vv.record(a) # Rotate camera for i in range(Nangles): a.camera.azimuth = 360 * float(i) / Nangles if a.camera.azimuth > 180: a.camera.azimuth -= 360 a.Draw() # Tell the axes to redraw f.DrawNow() # Draw the figure NOW, instead of waiting for GUI event loop # Export rec.Stop() rec.Export('teapot.gif')
line2.lc, line2.mc = 'y', 'r' # Display a legend a1.legend = "Astronaut's face", "Astronaut's helmet" # Create second axes (with a black background) a2 = vv.subplot(122) a2.bgcolor = 'k' a2.axis.axisColor = 'w' # Display a texture vol = vv.aVolume(2) # returns a test volume as a numpy array texture3d = vv.volshow(vol) # Display a mesh using one of the "solid" functions mesh = vv.solidTeapot((32, 32, 80), scaling=(50, 50, 50)) mesh.faceColor = 0.4, 1, 0.4 mesh.specular = 'r' # Set orthographic projection a2.camera.fov = 45 # Create labels for the axis a2.axis.xLabel = 'x-axis' a2.axis.yLabel = 'y-axis' a2.axis.zLabel = 'z-axis' # Enter main loop app = vv.use() # let visvis chose a backend for me app.Run()
# Display a legend a1.legend = "Lena's face", "Lena's shoulder" # Create second axes (with a black background) a2 = vv.subplot(122) a2.bgcolor = 'k' a2.axis.axisColor = 'w' # Display a texture vol = vv.aVolume(2) # returns a test volume as a numpy array texture3d = vv.volshow(vol) # Display a mesh using one of the "solid" functions mesh = vv.solidTeapot((32,32,80), scaling=(50,50,50)) mesh.faceColor = 0.4, 1, 0.4 mesh.specular = 'r' # Set orthographic projection a2.camera.fov = 45 # Create labels for the axis a2.axis.xLabel = 'x-axis' a2.axis.yLabel = 'y-axis' a2.axis.zLabel = 'z-axis' # Enter main loop app = vv.use() # let visvis chose a backend for me app.Run()
Parameters ---------- viewparams : dict View parameters to set. axes : Axes instance The axes the view parameters are for. Uses the current axes by default. keyword pairs View parameters to set. These take precidence. If neither viewparams or any keyword pairs are given, returns the current view parameters (as a dict). Otherwise, sets the view parameters given. """ if axes is None: axes = vv.gca() if viewparams or kw: axes.SetView(viewparams, **kw) else: return axes.GetView() if __name__ == '__main__': a = vv.gca() vv.solidTeapot() v = vv.view() # ... rotate the figure a bit and then call: vv.view(v) # Note that a.GetView() and a.SetView(v) are equivalent
#!/usr/bin/env python """ Example that demonstrates how movies can be recorded and exported to gif/swf/avi. This is not an interactive example, but a script. """ import visvis as vv # Create something to show, let's show a red teapot! mesh = vv.solidTeapot() mesh.faceColor = 'r' # Prepare Nangles = 36 a = vv.gca() f = vv.gcf() rec = vv.record(a) # Rotate camera for i in range(Nangles): a.camera.azimuth = 360 * float(i) / Nangles if a.camera.azimuth>180: a.camera.azimuth -= 360 a.Draw() # Tell the axes to redraw f.DrawNow() # Draw the figure NOW, instead of waiting for GUI event loop # Export
from visvis import Point, Pointset vv.figure() a = vv.gca() # Define points for the line pp = Pointset(3) pp.append(0,0,0); pp.append(0,1,0); pp.append(1,2,0); pp.append(0,2,1) # Create all solids box = vv.solidBox((0,0,0)) sphere = vv.solidSphere((3,0,0)) cone = vv.solidCone((6,0,0)) pyramid = vv.solidCone((9,0,0), N=4) # a cone with 4 faces is a pyramid cylinder = vv.solidCylinder((0,3,0),(1,1,2)) ring = vv.solidRing((3,3,0)) teapot = vv.solidTeapot((6,3,0)) line = vv.solidLine(pp+Point(9,3,0), radius = 0.2) # Let's put a face on that cylinder # This works because 2D texture coordinates are automatically generated for # the sphere, cone, cylinder and ring. im = vv.imread('lena.png') cylinder.SetTexture(im) # Make the ring green ring.faceColor = 'g' # Make the sphere dull sphere.specular = 0 sphere.diffuse = 0.4