Skip to content

Easing Functions

Module: terminaltexteffects.utils.easing

This module contains functions for easing calculations.

Functions:

Name Description
linear

Linear easing function.

in_sine

Ease in using a sine function.

out_sine

Ease out using a sine function.

in_out_sine

Ease in/out using a sine function.

in_quad

Ease in using a quadratic function.

out_quad

Ease out using a quadratic function.

in_out_quad

Ease in/out using a quadratic function.

in_cubic

Ease in using a cubic function.

out_cubic

Ease out using a cubic function.

in_out_cubic

Ease in/out using a cubic function.

in_quart

Ease in using a quartic function.

out_quart

Ease out using a quartic function.

in_out_quart

Ease in/out using a quartic function.

in_quint

Ease in using a quintic function.

out_quint

Ease out using a quintic function.

in_out_quint

Ease in/out using a quintic function.

in_expo

Ease in using an exponential function.

out_expo

Ease out using an exponential function.

in_out_expo

Ease in/out using an exponential function.

in_circ

Ease in using a circular function.

out_circ

Ease out using a circular function.

in_out_circ

Ease in/out using a circular function.

in_back

Ease in using a back function.

out_back

Ease out using a back function.

in_out_back

Ease in/out using a back function.

in_elastic

Ease in using an elastic function.

out_elastic

Ease out using an elastic function.

in_out_elastic

Ease in/out using an elastic function.

in_bounce

Ease in using a bounce function.

out_bounce

Ease out using a bounce function.

in_out_bounce

Ease in/out using a bounce function.

EasingFunction = typing.Callable[[float], float] module-attribute

EasingFunctions are Callable[[float], float] functions that take a float between 0 and 1 and return a float between 0 and 1.

in_back(progress_ratio)

Ease in using a back function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_back(progress_ratio: float) -> float:
    """
    Ease in using a back function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    c1 = 1.70158
    c3 = c1 + 1
    return c3 * progress_ratio**3 - c1 * progress_ratio**2

in_bounce(progress_ratio)

Ease in using a bounce function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the character

Source code in terminaltexteffects/utils/easing.py
def in_bounce(progress_ratio: float) -> float:
    """
    Ease in using a bounce function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the character
    """
    return 1 - out_bounce(1 - progress_ratio)

in_circ(progress_ratio)

Ease in using a circular function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_circ(progress_ratio: float) -> float:
    """
    Ease in using a circular function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return 1 - math.sqrt(1 - progress_ratio**2)

in_cubic(progress_ratio)

Ease in using a cubic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_cubic(progress_ratio: float) -> float:
    """
    Ease in using a cubic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return progress_ratio**3

in_elastic(progress_ratio)

Ease in using an elastic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_elastic(progress_ratio: float) -> float:
    """
    Ease in using an elastic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """

    c4 = (2 * math.pi) / 3
    if progress_ratio == 0:
        return 0
    elif progress_ratio == 1:
        return 1
    else:
        return -(2 ** (10 * progress_ratio - 10)) * math.sin((progress_ratio * 10 - 10.75) * c4)

in_expo(progress_ratio)

Ease in using an exponential function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_expo(progress_ratio: float) -> float:
    """
    Ease in using an exponential function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio == 0:
        return 0
    else:
        return 2 ** (10 * progress_ratio - 10)

in_out_back(progress_ratio)

Ease in/out using a back function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_back(progress_ratio: float) -> float:
    """
    Ease in/out using a back function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    c1 = 1.70158
    c2 = c1 * 1.525
    if progress_ratio < 0.5:
        return ((2 * progress_ratio) ** 2 * ((c2 + 1) * 2 * progress_ratio - c2)) / 2
    else:
        return ((2 * progress_ratio - 2) ** 2 * ((c2 + 1) * (progress_ratio * 2 - 2) + c2) + 2) / 2

in_out_bounce(progress_ratio)

Ease in/out using a bounce function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_bounce(progress_ratio: float) -> float:
    """
    Ease in/out using a bounce function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio < 0.5:
        return (1 - out_bounce(1 - 2 * progress_ratio)) / 2
    else:
        return (1 + out_bounce(2 * progress_ratio - 1)) / 2

in_out_circ(progress_ratio)

Ease in/out using a circular function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_circ(progress_ratio: float) -> float:
    """
    Ease in/out using a circular function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio < 0.5:
        return (1 - math.sqrt(1 - (2 * progress_ratio) ** 2)) / 2
    else:
        return (math.sqrt(1 - (-2 * progress_ratio + 2) ** 2) + 1) / 2

in_out_cubic(progress_ratio)

Ease in/out using a cubic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the

float

character

Source code in terminaltexteffects/utils/easing.py
def in_out_cubic(progress_ratio: float) -> float:
    """
    Ease in/out using a cubic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the
        character
    """
    if progress_ratio < 0.5:
        return 4 * progress_ratio**3
    else:
        return 1 - (-2 * progress_ratio + 2) ** 3 / 2

in_out_elastic(progress_ratio)

Ease in/out using an elastic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the character

Source code in terminaltexteffects/utils/easing.py
def in_out_elastic(progress_ratio: float) -> float:
    """
    Ease in/out using an elastic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the character
    """
    c5 = (2 * math.pi) / 4.5
    if progress_ratio == 0:
        return 0
    elif progress_ratio == 1:
        return 1
    elif progress_ratio < 0.5:
        return -(2 ** (20 * progress_ratio - 10) * math.sin((20 * progress_ratio - 11.125) * c5)) / 2
    else:
        return (2 ** (-20 * progress_ratio + 10) * math.sin((20 * progress_ratio - 11.125) * c5)) / 2 + 1

in_out_expo(progress_ratio)

Ease in/out using an exponential function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_expo(progress_ratio: float) -> float:
    """
    Ease in/out using an exponential function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio == 0:
        return 0
    elif progress_ratio == 1:
        return 1
    elif progress_ratio < 0.5:
        return 2 ** (20 * progress_ratio - 10) / 2
    else:
        return (2 - 2 ** (-20 * progress_ratio + 10)) / 2

in_out_quad(progress_ratio)

Ease in/out using a quadratic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_quad(progress_ratio: float) -> float:
    """
    Ease in/out using a quadratic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value

    """
    if progress_ratio < 0.5:
        return 2 * progress_ratio**2
    else:
        return 1 - (-2 * progress_ratio + 2) ** 2 / 2

in_out_quart(progress_ratio)

Ease in/out using a quartic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_quart(progress_ratio: float) -> float:
    """
    Ease in/out using a quartic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio < 0.5:
        return 8 * progress_ratio**4
    else:
        return 1 - (-2 * progress_ratio + 2) ** 4 / 2

in_out_quint(progress_ratio)

Ease in/out using a quintic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_quint(progress_ratio: float) -> float:
    """
    Ease in/out using a quintic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio < 0.5:
        return 16 * progress_ratio**5
    else:
        return 1 - (-2 * progress_ratio + 2) ** 5 / 2

in_out_sine(progress_ratio)

Ease in/out using a sine function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_out_sine(progress_ratio: float) -> float:
    """
    Ease in/out using a sine function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """

    return -(math.cos(math.pi * progress_ratio) - 1) / 2

in_quad(progress_ratio)

Ease in using a quadratic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_quad(progress_ratio: float) -> float:
    """
    Ease in using a quadratic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """

    return progress_ratio**2

in_quart(progress_ratio)

Ease in using a quartic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 representing the percentage

float

of the current waypoint speed to apply to the character

Source code in terminaltexteffects/utils/easing.py
def in_quart(progress_ratio: float) -> float:
    """
    Ease in using a quartic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 representing the percentage
        of the current waypoint speed to apply to the character
    """
    return progress_ratio**4

in_quint(progress_ratio)

Ease in using a quintic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_quint(progress_ratio: float) -> float:
    """
    Ease in using a quintic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return progress_ratio**5

in_sine(progress_ratio)

Ease in using a sine function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def in_sine(progress_ratio: float) -> float:
    """
    Ease in using a sine function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return 1 - math.cos((progress_ratio * math.pi) / 2)

linear(progress_ratio)

Linear easing function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def linear(progress_ratio: float) -> float:
    """
    Linear easing function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return progress_ratio

out_back(progress_ratio)

Ease out using a back function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_back(progress_ratio: float) -> float:
    """
    Ease out using a back function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    c1 = 1.70158
    c3 = c1 + 1
    return 1 + c3 * (progress_ratio - 1) ** 3 + c1 * (progress_ratio - 1) ** 2

out_bounce(progress_ratio)

Ease out using a bounce function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_bounce(progress_ratio: float) -> float:
    """
    Ease out using a bounce function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    n1 = 7.5625
    d1 = 2.75
    if progress_ratio < 1 / d1:
        return n1 * progress_ratio**2
    elif progress_ratio < 2 / d1:
        return n1 * (progress_ratio - 1.5 / d1) ** 2 + 0.75
    elif progress_ratio < 2.5 / d1:
        return n1 * (progress_ratio - 2.25 / d1) ** 2 + 0.9375
    else:
        return n1 * (progress_ratio - 2.625 / d1) ** 2 + 0.984375

out_circ(progress_ratio)

Ease out using a circular function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_circ(progress_ratio: float) -> float:
    """
    Ease out using a circular function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return math.sqrt(1 - (progress_ratio - 1) ** 2)

out_cubic(progress_ratio)

Ease out using a cubic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_cubic(progress_ratio: float) -> float:
    """
    Ease out using a cubic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return 1 - (1 - progress_ratio) ** 3

out_elastic(progress_ratio)

Ease out using an elastic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the character

Source code in terminaltexteffects/utils/easing.py
def out_elastic(progress_ratio: float) -> float:
    """
    Ease out using an elastic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 representing the percentage of the current waypoint speed to apply to the character
    """
    c4 = (2 * math.pi) / 3
    if progress_ratio == 0:
        return 0
    elif progress_ratio == 1:
        return 1
    else:
        return 2 ** (-10 * progress_ratio) * math.sin((progress_ratio * 10 - 0.75) * c4) + 1

out_expo(progress_ratio)

Ease out using an exponential function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_expo(progress_ratio: float) -> float:
    """
    Ease out using an exponential function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    if progress_ratio == 1:
        return 1
    else:
        return 1 - 2 ** (-10 * progress_ratio)

out_quad(progress_ratio)

Ease out using a quadratic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_quad(progress_ratio: float) -> float:
    """
    Ease out using a quadratic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value

    """
    return 1 - (1 - progress_ratio) * (1 - progress_ratio)

out_quart(progress_ratio)

Ease out using a quartic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_quart(progress_ratio: float) -> float:
    """
    Ease out using a quartic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return 1 - (1 - progress_ratio) ** 4

out_quint(progress_ratio)

Ease out using a quintic function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_quint(progress_ratio: float) -> float:
    """
    Ease out using a quintic function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return 1 - (1 - progress_ratio) ** 5

out_sine(progress_ratio)

Ease out using a sine function.

Parameters:

Name Type Description Default
progress_ratio float

the ratio of the current step to the maximum steps

required

Returns:

Name Type Description
float float

0 <= n <= 1 eased value

Source code in terminaltexteffects/utils/easing.py
def out_sine(progress_ratio: float) -> float:
    """
    Ease out using a sine function.

    Args:
        progress_ratio (float): the ratio of the current step to the maximum steps

    Returns:
        float: 0 <= n <= 1 eased value
    """
    return math.sin((progress_ratio * math.pi) / 2)