Easing Functions
Module: terminaltexteffects.utils.easing
Functions and Classes for easing calculations.
Classes:
| Name | Description |
|---|---|
EasingTracker |
Tracks the progression of an easing function over a set number of steps. |
SequenceEaser |
Eases over a sequence, tracking added, removed, and total elements |
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. |
make_easing |
Create a cubic Bezier easing function using the provided control points. |
EasingFunction = typing.Callable[[float], float]
module-attribute
EasingFunctions take a float between 0 and 1 and return a float between 0 and 1.
make_easing = functools.wraps(make_easing)(functools.lru_cache(maxsize=8192)(make_easing))
module-attribute
Create a cubic Bezier easing function using the provided control points.
The easing function maps an input progress ratio (0 to 1) to an output value (0 to 1) according to a cubic Bezier curve defined by four points: - Start point: (0, 0) - First control point: (x1, y1) - Second control point: (x2, y2) - End point: (1, 1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
Determines the horizontal position of the first control point. Smaller values make the curve start off steeper, while larger values delay the initial acceleration. |
required |
y1
|
float
|
Determines the vertical position of the first control point. Smaller values create a gentler ease-in effect; larger values increase the initial acceleration. |
required |
x2
|
float
|
Determines the horizontal position of the second control point. Larger values extend the period of change, affecting how late the acceleration or deceleration begins. |
required |
y2
|
float
|
Determines the vertical position of the second control point. Larger values can create a more abrupt ease-out effect; smaller values result in a smoother finish. |
required |
Note: Use a resource such as cubic-bezier.com to design an appropriate easing curve for your needs.
Returns:
| Name | Type | Description |
|---|---|---|
EasingFunction |
EasingFunction
|
A function that takes a progress_ratio (0 <= progress_ratio <= 1) and returns |
EasingFunction
|
the eased value computed from the cubic Bezier curve. |
EasingTracker
dataclass
Describe the progression of items as an easing function is applied over a sequence.
Attributes:
| Name | Type | Description |
|---|---|---|
easing_function |
EasingFunction
|
The easing function being tracked. |
total_steps |
int
|
The total number of steps for the easing function. |
current_step |
int
|
The current step in the easing progression. |
progress_ratio |
float
|
The ratio of the current step to the total steps. |
step_delta |
float
|
The change in eased value from the last step to the current step. |
eased_value |
float
|
The current eased value based on the easing function and progress ratio. |
Methods:
| Name | Description |
|---|---|
step |
Advance the easing tracker by one step and return the new eased value. |
is_complete |
Check if the easing tracker has completed all steps. |
Source code in terminaltexteffects/utils/easing.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
__iter__()
Iterate over eased values until completion.
Yields:
| Name | Type | Description |
|---|---|---|
float |
float
|
The eased value at each step. |
__post_init__(clamp)
Initialize the EasingTracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clamp
|
bool
|
If True, clamp the eased value between 0 and 1. Defaults to False. |
required |
Source code in terminaltexteffects/utils/easing.py
is_complete()
Check if the easing tracker has completed all steps.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all steps have been completed, False otherwise. |
reset()
Reset the easing tracker to the initial state.
step()
Advance the easing tracker by one step.
If the current step is less than the total steps, increment the current step, update the progress ratio, compute the new eased value using the easing function, and calculate the step delta.
If clamp is enabled, the eased value is constrained between 0 and 1.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The new eased value after advancing one step. |
Source code in terminaltexteffects/utils/easing.py
SequenceEaser
dataclass
Bases: Generic[_T]
Eases over a sequence, tracking added, removed, and total elements.
Attributes:
| Name | Type | Description |
|---|---|---|
sequence |
Sequence[_T]
|
The sequence to ease over. |
easing_function |
EasingFunction
|
The easing function to use. |
total_steps |
int
|
The total number of steps for the easing function. |
added |
Sequence[_T]
|
Elements added in the current step. |
removed |
Sequence[_T]
|
Elements removed in the current step. |
total |
Sequence[_T]
|
Current active elements based on eased length. |
Source code in terminaltexteffects/utils/easing.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
__post_init__()
is_complete()
Check if the easing over the sequence is complete.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all steps have been completed, False otherwise. |
reset()
Reset the SequenceEaser to the initial state.
step()
Advance the easing tracker by one step and update added, removed, and total elements.
Returns:
| Type | Description |
|---|---|
Sequence[_T]
|
typing.Sequence[_T]: The elements added in the current step. |
Source code in terminaltexteffects/utils/easing.py
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 |