EXAMPLES: We plot a circle shooting up to the right:
sage: a = animate([circle((i,i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)],
... xmin=0,ymin=0,xmax=2,ymax=2,figsize=[2,2])
sage: a.show() # optional -- requires convert command
Bases: sage.structure.sage_object.SageObject
Return an animation of a sequence of plots of objects.
INPUT:
EXAMPLES:
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.3)],
... xmin=0, xmax=2*pi, figsize=[2,1])
sage: a
Animation with 21 frames
sage: a[:5]
Animation with 5 frames
sage: a.show() # optional -- requires convert command
sage: a[:5].show() # optional
The show function takes arguments to specify the delay between frames (measured in hundredths of a second, default value 20) and the number of iterations (default value 0, which means to iterate forever). To iterate 4 times with half a second between each frame:
sage: a.show(delay=50, iterations=4) # optional
An animation of drawing a parabola:
sage: step = 0.1
sage: L = Graphics()
sage: v = []
sage: for i in srange(0,1,step):
... L += line([(i,i^2),(i+step,(i+step)^2)], rgbcolor=(1,0,0), thickness=2)
... v.append(L)
sage: a = animate(v, xmin=0, ymin=0)
sage: a.show() # optional -- requires convert command
sage: show(L)
TESTS: This illustrates that ticket #2066 is fixed (setting axes ranges when an endpoint is 0):
sage: animate([plot(sin, -1,1)], xmin=0, ymin=0)._Animation__kwds['xmin']
0
Returns an animated gif composed from rendering the graphics objects in self.
This function will only work if the ImageMagick command line tools package is installed, i.e., you have the “convert” command.
INPUT:
If savefile is not specified: in notebook mode, display the animation; otherwise, save it to a default file name.
EXAMPLES:
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
... xmin=0, xmax=2*pi, figsize=[2,1])
sage: a.gif() # optional -- requires convert command
sage: a.gif(delay=35, iterations=3) # optional
sage: a.gif(savefile='my_animation.gif') # optional
sage: a.gif(savefile='my_animation.gif', show_path=True) # optional
Animation saved to .../my_animation.gif.
Note
If ImageMagick is not installed, you will get an error message like this:
/usr/local/share/sage/local/bin/sage-native-execute: 8: convert:
not found
Error: ImageMagick does not appear to be installed. Saving an
animation to a GIF file or displaying an animation requires
ImageMagick, so please install it and try again.
See www.imagemagick.org, for example.
AUTHORS:
Return a graphics array with the given number of columns with plots of the frames of this animation.
EXAMPLES:
sage: E = EllipticCurve('37a')
sage: v = [E.change_ring(GF(p)).plot(pointsize=30) for p in [97, 101, 103, 107]]
sage: a = animate(v, xmin=0, ymin=0)
sage: a
Animation with 4 frames
sage: a.show() # optional -- requires convert command
sage: g = a.graphics_array()
sage: print g
Graphics Array of size 1 x 3
sage: g.show(figsize=[4,1]) # optional
sage: g = a.graphics_array(ncols=2)
sage: print g
Graphics Array of size 2 x 2
sage: g.show('sage.png') # optional
Return the absolute path to a temp directory that contains the rendered PNG’s of all the images in this animation.
EXAMPLES:
sage: a = animate([plot(x^2 + n) for n in range(4)])
sage: d = a.png()
sage: v = os.listdir(d); v.sort(); v
['00000000.png', '00000001.png', '00000002.png', '00000003.png']
Save this animation into a gif or sobj file.
INPUT:
If filename is None, then in notebook mode, display the animation; otherwise, save the animation to a gif file. If filename ends in ‘.gif’, save to a gif file. If filename ends in ‘.sobj’, save to an sobj file.
In all other cases, print an error.
EXAMPLES:
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
... xmin=0, xmax=2*pi, figsize=[2,1])
sage: a.save() # optional -- requires convert command
sage: a.save('wave.gif') # optional
sage: a.save('wave.gif', show_path=True) # optional
Animation saved to file .../wave.gif.
sage: a.save('wave0.sobj') # optional
sage: a.save('wave1.sobj', show_path=True) # optional
Animation saved to file wave1.sobj.
Show this animation.
INPUT:
Note
Currently this is done using an animated gif, though this could change in the future. This requires that the ImageMagick command line tools package be installed, i.e., that you have the convert command.
EXAMPLES:
sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)],
... xmin=0, xmax=2*pi, figsize=[2,1])
sage: a.show() # optional -- requires convert command
The preceding will loop the animation forever. If you want to show only three iterations instead:
sage: a.show(iterations=3) # optional
To put a half-second delay between frames:
sage: a.show(delay=50) # optional
Note
If ImageMagick is not installed, you will get an error message like this:
/usr/local/share/sage/local/bin/sage-native-execute: 8: convert:
not found
Error: ImageMagick does not appear to be installed. Saving an
animation to a GIF file or displaying an animation requires
ImageMagick, so please install it and try again.
See www.imagemagick.org, for example.