Interpolating

ahlive can make animations alive.

interp

There are various interp methods built-in.

[1]:
import ahlive as ah
for interp in ah.easing.INTERPS:
    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()
gifsicle: warning: trivial adaptive palette (only 84 colors in source)

ease

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

[2]:
import ahlive as ah

for ease in ah.easing.EASES:
    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()

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.

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

Lower number of frames will be more choppy.

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

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.

[5]:
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)
[5]:

traceback backtracks the original path to the initial state.

[6]:
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)
[6]:

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

[7]:
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)
[7]:

stand-alone

The Easing class be applied to any generic Iterables.

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

array = np.array([0, 1, 3])
easing = Easing(interp='cubic', ease='in')
easing.interpolate(array)
[8]:
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]])