Package sage :: Package plot :: Module animate :: Class Animation
[hide private]
[frames] | no frames]

Class Animation

source code

                      object --+    
                               |    
structure.sage_object.SageObject --+
                                   |
                                  Animation


Return an animation of a sequence of plots of objects.

INPUT:
    v -- list of SAGE objects. These should preferably be graphics objects,
         but if they aren't then plot is called on them.
    xmin, xmax, ymin, ymax -- the ranges of the x and y axis.
    **kwds -- all additional inputs are passed onto the rendering
          command.  E.g., use figsize to adjust the resolution and
          aspect ratio.

EXAMPLES:
    sage: a = animate([sin(x + float(k)) for k in srange(0,4,0.3)], 
    ...                xmin=0, xmax=2*pi, figsize=[2,1]) # optional -- requires convert command
    sage: a # optional
    Animation with 14 frames
    sage: a[:5] # optional
    Animation with 5 frames
    sage: a.show()          # optional
    sage: a[:5].show()      # optional

We draw 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()
    sage: show(L)

TESTS:
This illustrates ticket \#2066 is fixed (setting axes ranges when an endpoint is 0):
    sage: animate(plot(sin, -1,1), xmin=0, ymin=0)._Animation__xmin
    0    



Instance Methods [hide private]
 
__init__(self, v, xmin=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., xmax=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., ymin=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., ymax=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__getitem__(self, i)
Get a frame from an animation.
source code
 
__getslice__(self, *args)
Slice this animation returning a subanimation.
source code
 
_set_axes(self) source code
 
_repr_(self) source code
 
__add__(self, other)
Add two animations.
source code
 
__mul__(self, other)
Multiply two animations.
source code
 
png(self, dir=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Return the absolute path to a temp directory that contains the rendered png's of all the images in this animation.
source code
 
graphics_array(self, ncols=3)
Return a graphics array with the given number of columns with plots of the frames of this animation.
source code
 
gif(self, delay=20, outfile=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., iterations=0)
Returns an animated gif composed from rendering the graphics objects in self.
source code
 
show(self, delay=20, iterations=0)
Show this animation.
source code
 
save(self, filename=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
File: sage/structure/sage_object.pyx (starting at line 130) Save self to the given filename.
source code

Inherited from structure.sage_object.SageObject: __hash__, __new__, __repr__, _axiom_, _axiom_init_, _gap_, _gap_init_, _gp_, _gp_init_, _interface_, _interface_init_, _interface_is_cached_, _kash_, _kash_init_, _macaulay2_, _macaulay2_init_, _magma_, _magma_init_, _maple_, _maple_init_, _mathematica_, _mathematica_init_, _maxima_, _maxima_init_, _octave_, _octave_init_, _pari_, _pari_init_, _r_init_, _sage_, _singular_, _singular_init_, category, db, dump, dumps, plot, rename, reset_name, version

Inherited from object: __delattr__, __getattribute__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, v, xmin=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., xmax=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., ymin=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., ymax=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__getitem__(self, i)
(Indexing operator)

source code 

Get a frame from an animation.

EXAMPLES:
    sage: a = animate([x, x^2, x^3, x^4]) # optional -- requires convert command
    sage: a[2].show()       # optional

__getslice__(self, *args)
(Slicling operator)

source code 

Slice this animation returning a subanimation.

EXAMPLES:
    sage: a = animate([circle((i,-i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)], 
    ...               xmin=0,ymin=-2,xmax=2,ymax=0,figsize=[2,2]) # optional -- requires convert command
    ...
    sage: a # optional
    Animation with 10 frames
    sage: a.show() # optional
    sage: a[3:7] # optional
    Animation with 4 frames
    sage: a[3:7].show() # optional

__add__(self, other)
(Addition operator)

source code 

Add two animations.  This has the effect of
superimposing the two animinations frame-by-frame.

EXAMPLES:
We add and multiply two animations.

    sage: a = animate([circle((i,0),1) for i in srange(0,2,0.4)], 
    ...                xmin=0, ymin=-1, xmax=3, ymax=1, figsize=[2,1]) # optional -- requires convert command
    sage: a.show()   # optional
    sage: b = animate([circle((0,i),1,hue=0) for i in srange(0,2,0.4)], 
    ...                xmin=0, ymin=-1, xmax=1, ymax=3, figsize=[1,2]) # optional
    sage: b.show() # optional
    sage: (a*b).show()    # optional
    sage: (a+b).show()    # optional

__mul__(self, other)

source code 

Multiply two animations.  This has the effect of
appending the two animinations (the second comes
after the first).

EXAMPLES:
We add and multiply two animations.
    sage: a = animate([circle((i,0),1,thickness=20*i) for i in srange(0,2,0.4)], 
    ...                xmin=0, ymin=-1, xmax=3, ymax=1, figsize=[2,1], axes=False) # optional -- requires convert command
    sage: a.show()     # optional
    sage: b = animate([circle((0,i),1,hue=0,thickness=20*i) for i in srange(0,2,0.4)], 
    ...                xmin=0, ymin=-1, xmax=1, ymax=3, figsize=[1,2], axes=False) # optional
    sage: b.show()             # optional
    sage: (a*b).show()         # optional
    sage: (a+b).show()         # optional

png(self, dir=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

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)]) # optional -- requires convert command
    sage: d = a.png() # optional  -- directory where the files are
    sage: v = os.listdir(d); v.sort(); v # optional
    ['00000000.png', '00000001.png', '00000002.png', '00000003.png']

graphics_array(self, ncols=3)

source code 

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) # optional -- requires convert command
    sage: a # optional
    Animation with 4 frames
    sage: a.show()        # optional

    sage: g = a.graphics_array() # optional
    sage: print g # optional
    Graphics Array of size 1 x 3
    sage: g.show(figsize=[4,1]) # optional

    sage: g = a.graphics_array(ncols=2) # optional
    sage: print g # optional
    Graphics Array of size 2 x 2
    sage: g.show('sage.png')         # optional

gif(self, delay=20, outfile=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., iterations=0)

source code 

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 ``\code{convert}'' command.

INPUT:
    delay -- (default: 20) delay in hundredths of a second between frames
    outfile -- file that the animated gif gets saved to
    iterations -- integer (default: 0); number of iterations of
                  animation.  If 0, loop forever. 

AUTHOR:
    -- William Stein

show(self, delay=20, iterations=0)

source code 

Show this animation.

Currently this is done by default using an animated gif, though this
could change in the future. 

save(self, filename=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 
File: sage/structure/sage_object.pyx (starting at line 130)

Save self to the given filename.

EXAMPLES:
    sage: f = x^3 + 5
    sage: f.save(SAGE_TMP + '/file')
    sage: load(SAGE_TMP + '/file.sobj')
    x^3 + 5

Overrides: structure.sage_object.SageObject.save
(inherited documentation)