Example #1
0
 def record(self, event):
     """ keys to record, stop, continue save  clear r of figure
                   r       t      y      m     q
     """
     if event.text == 'r':
         self.r = vv.record(self.fig)
         print('recording..')
     if event.text == 't':
         self.r.Stop()
         print('stop recording')
     if event.text == 'y':
         self.r.Continue()
         print('continue recording')
     if event.text == 'q':
         self.r.Clear()
         print('clear recording')
     if event.text == 'm':  # save
         if self.filename is None:
             now = datetime.datetime.now()
             self.filename = now.strftime(
                 "%Y-%m-%d_%H.%M") + '_recorded' + '.' + self.fileformat
         if self.frameRate is None:
             imageio.mimsave(os.path.join(self.dirsave, self.filename),
                             self.r.GetFrames())
         else:
             imageio.mimsave(os.path.join(self.dirsave, self.filename),
                             self.r.GetFrames(),
                             fps=self.frameRate)
         print('Recorded movie stored')
Example #2
0
# try the differtent render styles, for examample 
# "t.renderStyle='iso'" or "t.renderStyle='ray'"
# If the drawing hangs, your video drived decided to render in software mode.
# This is unfortunately (as far as I know) not possible to detect. 
# It might help if your data is shaped a power of 2.

# Get axes and set camera to orthographic mode (with a field of view of 70)
a = vv.gcf()
f = vv.gca()#fqwang

#a.camera.fov = 45

# Create colormap editor wibject.
vv.ColormapEditor(a)

rec = vv.record(f)

# Rotate camera
#fqwang
Nangles = 36
for i in range(Nangles):
    f.camera.azimuth = 360 * float(i) / Nangles
    if f.camera.azimuth>180:
        f.camera.azimuth -= 360
    f.Draw() # Tell the axes to redraw 
    a.DrawNow() # Draw the figure NOW, instead of waiting for GUI event loop


# Export
rec.Stop()
rec.Export('plot.swf')
Example #3
0
# Zoom
axes.SetLimits(margin=0.0)
axes.SetLimits(margin=0.0, rangeX=(-1, 1))

# Control lighting
#axes.bgcolor='k'
# axes.light0.ambient = 0.0 # 0.2 is default for light 0
# axes.light0.diffuse = 0.0 # 1.0 is default
axes.light0.Off()
light1 = axes.lights[1]
light1.On()
light1.ambient = 0.8
light1.diffuse = 1.0
light1.isDirectional = True
light1.position = (2, -4, 2, 0)
rec = vv.record(vv.gcf())

# Timer for controlling rotation speed
timer = vv.Timer(axes, 100, False)
timer.Bind(onTimer)
timer.Start(interval=1)
app = vv.use()
app.Run()

# Output movie to gif
rec.Stop()
rec.Export('movie.gif')

# Old code that used matplotlib, which is like 10 times slower, but left in
# since visvis is discontinued
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')
""" NOTES

A note on a.Draw()
Example #5
0
def record(ob):
    """ record(object)
    Take a snapshot of the given figure or axes after each draw.
    A Recorder instance is returned, with which the recording can
    be stopped, continued, and exported to GIF, SWF or AVI.
    """
    
    # establish wheter we can record that
    if not isinstance(ob, (vv.BaseFigure, vv.Axes)):
        raise ValueError("The given object is not a figure nor an axes.")
    
    # create recorder
    return Recorder(ob)    


if __name__ == '__main__':
    import time
    l = vv.plot([1,2,3,1,4])
    rec = vv.record(vv.gcf())
    for i in range(20):
        l.SetYdata([1+i/10.0, 2,3,1,4])
        vv.processEvents() # Process gui events
        time.sleep(0.1)
    # Export to swf, gif or avi
    fname = 'recordExample' # note: set location to an existing directory
    for ext in ['.swf', '.gif', '.avi']:
        try:
            rec.Export(fname+ext)
        except Exception:
            print('could not do %s' % ext)
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')