# Revision history [back]

For any animation, you should write a function to produce the successive frames. Something like the following, for example:

sage: var('t')
t
sage: c1=parametric_plot3d((t,0,0),(0,1),thickness=2)
sage: c2=parametric_plot3d((t,t^2,t^3),(0,1),thickness=2)
def frame(i):
return c1+c2+sphere(center=(i,i^2,i^3),size=.03,color='black')+sphere(center=(0,0,0),size=.03,color='black')


Then you can make a list of frames as

frames = [frame(i) for i in sxrange(0,1,.1)]


The animate command can then produce a simple gif:

A = animate(frames)
A.show()


For a longer animation or different format, you should save the frames as separate images and then combine them into a video with ImageMagick or ffmpeg.

For any animation, you should write a function to produce the successive frames. Something like the following, for example:

sage: var('t')
t
sage: c1=parametric_plot3d((t,0,0),(0,1),thickness=2)
sage: c2=parametric_plot3d((t,t^2,t^3),(0,1),thickness=2)
def frame(i):
return c1+c2+sphere(center=(i,i^2,i^3),size=.03,color='black')+sphere(center=(0,0,0),size=.03,color='black')


Then you can make a list of frames as

frames = [frame(i) for i in sxrange(0,1,.1)]


The animate command can then produce a simple gif:

A = animate(frames)
A.show()


For a longer animation or different format, you should save the frames as separate images and then (outside of Sage) combine them into a video with ImageMagick or ffmpeg.

For any animation, you should write a function to produce the successive frames. Something like the following, for example:

sage: var('t')
t
sage: c1=parametric_plot3d((t,0,0),(0,1),thickness=2)
sage: c2=parametric_plot3d((t,t^2,t^3),(0,1),thickness=2)
def frame(i):
return c1+c2+sphere(center=(i,i^2,i^3),size=.03,color='black')+sphere(center=(0,0,0),size=.03,color='black')


Then you can make a list of frames as

frames = [frame(i) for i in sxrange(0,1,.1)]


The To animate them, use a modified version of @kcrisman 's answer to a similar question:

DATA = tmp_dir() # in the notebook, this will already be set to some temporary directory
for i in range(len(frames)):
saved[i].save(filename=DATA+'mypic%08d.png'%i)

os.system('cd '+DATA+'; convert -delay %s -loop %s *.png "Done.gif"'%(int(100),int(2)))
os.system('ls '+DATA)


Note that with the patch at Trac 12827 applied, you can use the animate command can then produce a simple gif:directly:

A = animate(frames)
A.show()


For a longer animation or different format, you should save saving the frames as separate images is probably better. The convert utility from ImageMagick works great for gifs, and then (outside of Sage) combine them into a ffmpeg is good for other video with ImageMagick or ffmpeg.

formats.

 4 No.4 Revision kcrisman 11887 ●36 ●122 ●237

For any animation, you should write a function to produce the successive frames. Something like the following, for example:

sage: var('t')
t
sage: c1=parametric_plot3d((t,0,0),(0,1),thickness=2)
sage: c2=parametric_plot3d((t,t^2,t^3),(0,1),thickness=2)
def frame(i):
return c1+c2+sphere(center=(i,i^2,i^3),size=.03,color='black')+sphere(center=(0,0,0),size=.03,color='black')


Then you can make a list of frames as

frames = [frame(i) for i in sxrange(0,1,.1)]


To animate them, use a modified version of @kcrisman 's answer to a similar question:

DATA = tmp_dir() # in the notebook, this will already be set to some temporary directory
for i in range(len(frames)):
saved[i].save(filename=DATA+'mypic%08d.png'%i)

os.system('cd '+DATA+'; convert -delay %s -loop %s *.png "Done.gif"'%(int(100),int(2)))
os.system('ls '+DATA)


Note that with the patch at Trac 12827 12827 applied, you can use the animate command directly:

A = animate(frames)
A.show()


For a longer animation or different format, saving the frames as separate images is probably better. The convert utility from ImageMagick works great for gifs, and ffmpeg is good for other video formats.