Animating#
To animate or not to animate, that is the question.
animate#
By default, animate
is set to True
. However, if set to False
, the individual frames can be saved to a directory named after save
.
[1]:
import ahlive as ah
ah.Array([0, 1], [4, 5], save='exporting_tutorial', animate=False).render()
[1]:
['/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/01.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/02.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/03.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/04.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/05.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/06.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/07.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/08.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/09.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/10.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/11.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/12.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/13.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/14.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/15.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/16.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/17.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/18.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/19.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/20.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/21.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/22.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/23.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/24.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/25.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/26.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/27.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/28.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/29.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/30.png',
'/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/latest/docs/source/customizations/exporting_tutorial/31.png']
Or, rather than saving to disk, the ouput can be piped to other packages, like panel.
[2]:
import ahlive as ah
import panel as pn
pn.extension()
images = ah.Array([0, 1], [4, 5], animate=False).render()
pngs = [pn.pane.PNG(image, name=str(i)) for i, image in enumerate(images)]
tabs = pn.Tabs(*pngs)
player = pn.widgets.Player(align='center', end=len(tabs))
link = player.jslink(tabs, value='active', bidirectional=True)
pn.Column(tabs, player).servable()
[2]:
Besides a bool
, animate
also accepts a Iterable
, str
, slice
, or int
.
If an Iterable
is passed to animate
, only those frames will be animated.
[3]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate=[1, 25]).render()
gifsicle: warning: trivial adaptive palette (only 27 colors in source)
[3]:
If head
(or tail
) is passed, the first (or last) 10 frames will be animated and fps
will be set to 1
.
[4]:
import ahlive as ah
ah.Array([0, 1], [4, 5], animate='head').render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/ahlive-1.0.4.post1+dirty-py3.11.egg/ahlive/animation.py:2032: UserWarning: durations is not supported with fps set
warnings.warn("durations is not supported with fps set")
gifsicle: warning: trivial adaptive palette (only 42 colors in source)
[4]:
A number can be suffixed to control the number of frames.
[5]:
import ahlive as ah
ah.Array([0, 1], [4, 5], animate='head_5').render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/ahlive-1.0.4.post1+dirty-py3.11.egg/ahlive/animation.py:2032: UserWarning: durations is not supported with fps set
warnings.warn("durations is not supported with fps set")
gifsicle: warning: trivial adaptive palette (only 37 colors in source)
[5]:
Any arbitrary str
will animate 10 frames evenly distributed.
[6]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate='test').render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/ahlive-1.0.4.post1+dirty-py3.11.egg/ahlive/animation.py:2032: UserWarning: durations is not supported with fps set
warnings.warn("durations is not supported with fps set")
gifsicle: warning: trivial adaptive palette (only 42 colors in source)
[6]:
If a slice
is passed to animate
, only those frames in between the start
and stop
will be animated at step
intervals.
[7]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate=slice(0, 40, 5)).render()
gifsicle: warning: trivial adaptive palette (only 27 colors in source)
[7]:
If an int
is passed, only that frame will be rendered, i.e. a static image is produced.
[8]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate=28).render()
[8]:
durations#
The animations can be slowed down or sped up using durations
.
If a scalar is passed to durations
all frames will be delayed by the specified value in seconds.
[9]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], durations=2).render()
gifsicle: warning: trivial adaptive palette (only 53 colors in source)
[9]:
durations
is only supported for GIFs!
durations
can also be specified as an Iterable
. The length must match the number of states.
[10]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], durations=[1e-6, 1, 10]).render()
gifsicle: warning: trivial adaptive palette (only 53 colors in source)
[10]:
durations
only delay the original states. To delay the interpolated frames, transition_frames
can be set through config
.
[11]:
import ahlive as ah
arr = ah.Array([0, 1], [4, 5])
arr = arr.config('durations', transition_frames=0.5)
arr.render()
gifsicle: warning: trivial adaptive palette (only 44 colors in source)
[11]:
Setting final_frame
can delay the last frame before the animation restarts.
[12]:
import ahlive as ah
arr = ah.Array([0, 1], [4, 5])
arr = arr.config('durations', final_frame=3)
arr.render()
gifsicle: warning: trivial adaptive palette (only 44 colors in source)
[12]:
fps#
Alternatively, animations can be slowed down or sped up using durations.
fps
, or frames per second, is the inverse of durations
, e.g. 10 fps
== 1 / 10 durations
.
[13]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], fps=10).render()
gifsicle: warning: trivial adaptive palette (only 53 colors in source)
[13]:
loop#
The number of times the animation plays can be limited with loop
.
[14]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], loop=1).render()
gifsicle: warning: trivial adaptive palette (only 53 colors in source)
[14]: