Interpolating#

ahlive can make animations alive.

interp#

There are various interp methods built-in.

[1]:
import ahlive as ah
interp = "linear"
ah.Array(
    [0, 1], [1, 1], s=[18, 488],
    interp=interp, inline_labels=interp,
    xmargins=(0.1, 0.5), ymargins=0, figsize=(10, 0.75),
    revert='traceback', style="bare", watermark=" "
).render()
[1]:
[2]:
import ahlive as ah
interp = "cubic"
ah.Array(
    [0, 1], [1, 1], s=[18, 488],
    interp=interp, inline_labels=interp,
    xmargins=(0.1, 0.5), ymargins=0, figsize=(10, 0.75),
    revert='traceback', style="bare", watermark=" "
).render()
[2]:
[3]:
import ahlive as ah
interp = "elastic"
ah.Array(
    [0, 1], [1, 1], s=[18, 488],
    interp=interp, inline_labels=interp,
    xmargins=(0.1, 0.5), ymargins=0, figsize=(10, 0.75),
    revert='traceback', style="bare", watermark=" "
).render()
[3]:

For a full list:

[4]:
import ahlive as ah
ah.easing.INTERPS
[4]:
['fill',
 'linear',
 'cubic',
 'exponential',
 'quadratic',
 'quartic',
 'quintic',
 'circular',
 'sine',
 'bounce',
 'elastic',
 'back']

ease#

There are also three easing methods for each of these interp methods.

[5]:
import ahlive as ah

ease = "in_out"
ah.Array(
    [0, 1], [1, 1], s=[18, 488],
    interp="cubic", ease=ease, inline_labels=ease,
    xmargins=(0.1, 0.5), ymargins=0, figsize=(10, 0.75),
    revert='traceback', style="bare", watermark=" "
).render()
[5]:
[6]:
import ahlive as ah

ease = "in"
ah.Array(
    [0, 1], [1, 1], s=[18, 488],
    interp="cubic", ease=ease, inline_labels=ease,
    xmargins=(0.1, 0.5), ymargins=0, figsize=(10, 0.75),
    revert='traceback', style="bare", watermark=" "
).render()
[6]:
[7]:
import ahlive as ah

ease = "out"
ah.Array(
    [0, 1], [1, 1], s=[18, 488],
    interp="cubic", ease=ease, inline_labels=ease,
    xmargins=(0.1, 0.5), ymargins=0, figsize=(10, 0.75),
    revert='traceback', style="bare", watermark=" "
).render()
[7]:

frames#

The number of frames per transition to the next base state can be controlled using frames.

Higher number of frames will be more smooth.

[8]:
import ahlive as ah
ah.Array([0, 1], [0, 1], frames=25).render()
gifsicle: warning: trivial adaptive palette (only 192 colors in source)
[8]:

Lower number of frames will be more choppy.

[9]:
import ahlive as ah
ah.Array([0, 1], [0, 1], frames=5).render()
gifsicle: warning: trivial adaptive palette (only 187 colors in source)
[9]:

fps can be set alongside frames to control the length of the animation.

revert#

There are three revert methods.

boomerang finds the shortest path to the initial state.

[10]:
import ahlive as ah
ah.Array(
    [0, 50, 1000], [0, 1000, 5000], revert='boomerang'
).render()
gifsicle: warning: trivial adaptive palette (only 200 colors in source)
[10]:

traceback backtracks the original path to the initial state.

[11]:
import ahlive as ah
ah.Array(
    [0, 50, 1000], [0, 1000, 5000], revert='traceback'
).render()
gifsicle: warning: trivial adaptive palette (only 201 colors in source)
[11]:

rollback is like traceback, but disregards the original path’s durations.

[12]:
import ahlive as ah
ah.Array(
    [0, 50, 1000], [0, 1000, 5000], revert='rollback'
).render()
gifsicle: warning: trivial adaptive palette (only 201 colors in source)
[12]:

stand-alone#

The Easing class be applied to any generic Iterables.

[13]:
import numpy as np
from ahlive import Easing

array = np.array([0, 1, 3])
easing = Easing(interp='cubic', ease='in')
easing.interpolate(array)
[13]:
array([[0.00000000e+00, 1.45793847e-04, 1.16635078e-03, 3.93643388e-03,
        9.33080624e-03, 1.82242309e-02, 3.14914711e-02, 5.00072897e-02,
        7.46464499e-02, 1.06283715e-01, 1.45793847e-01, 1.94051611e-01,
        2.51931768e-01, 3.20309083e-01, 4.00058318e-01, 4.92054235e-01,
        5.97171599e-01, 7.16285173e-01, 8.50269719e-01, 1.00000000e+00,
        1.00000000e+00, 1.00029159e+00, 1.00233270e+00, 1.00787287e+00,
        1.01866161e+00, 1.03644846e+00, 1.06298294e+00, 1.10001458e+00,
        1.14929290e+00, 1.21256743e+00, 1.29158769e+00, 1.38810322e+00,
        1.50386354e+00, 1.64061817e+00, 1.80011664e+00, 1.98410847e+00,
        2.19434320e+00, 2.43257035e+00, 2.70053944e+00, 3.00000000e+00,
        3.00000000e+00]])