Animations with mayavi and moviepy

Poul Riis priisdk at gmail.com
Wed May 11 02:33:17 EDT 2016


The animation example below (taken from http://zulko.github.io/blog/2014/11/29/data-animations-with-python-and-moviepy/)
stops after producing and displaying the 41 frames. In stead, after producing the 41 frames I want to make it loop continuously. I have googled and googled and googled and still not found out how to do it. I guess that it is very simple but how?

The program prints out some rather uninteresting information - how can I suppress that?


Poul Riis




import numpy as np
import mayavi.mlab as mlab
import  moviepy.editor as mpy

duration= 2 # duration of the animation in seconds (it will loop)

# MAKE A FIGURE WITH MAYAVI

fig_myv = mlab.figure(size=(220,220), bgcolor=(1,1,1))
X, Y = np.linspace(-2,2,200), np.linspace(-2,2,200)
XX, YY = np.meshgrid(X,Y)
ZZ = lambda d: np.sinc(XX**2+YY**2)+np.sin(XX+d)

# ANIMATE THE FIGURE WITH MOVIEPY, WRITE AN ANIMATED GIF

def make_frame(t):
    mlab.clf() # clear the figure (to reset the colors)
    mlab.mesh(YY,XX,ZZ(2*np.pi*t/duration), figure=fig_myv)
    return mlab.screenshot(antialiased=True)

animation = mpy.VideoClip(make_frame, duration=duration)
animation.write_gif("sinc.gif", fps=20)






More information about the Python-list mailing list