PyTweening
PyTweening is a lightweight Python library providing a collection of tweening (also known as easing) functions. These functions allow for smooth, non-linear interpolation between values, commonly used to create natural-looking animations in graphical applications or games. The library is currently at version 1.2.0 and receives periodic updates to enhance functionality and maintain compatibility.
Warnings
- gotcha Tweening functions generally expect an input 'n' between 0.0 and 1.0 representing the progress of the animation. While the library itself doesn't strictly enforce this range check internally anymore, providing values outside of this range might lead to unexpected results, especially for functions designed to stay within the 0.0-1.0 output range.
- gotcha When using iterator functions like `pytweening.iterLinear` to generate sequences of points, some floating-point rounding errors may naturally occur in the output coordinates. This is a common characteristic of floating-point arithmetic.
- gotcha PyTweening provides client-side animation logic. When integrating into multi-client environments (e.g., online games) or systems involving physics, performing local client-side tweens on shared objects can lead to desynchronization. Different clients might observe inconsistent object positions due to network latency or varying execution times.
Install
-
pip install pytweening
Imports
- pytweening
import pytweening
Quickstart
import pytweening
# Get a linear tween value at 50% progress
linear_value = pytweening.linear(0.5)
print(f"Linear tween at 0.5: {linear_value}")
# Get an ease-in-quad tween value at 50% progress
ease_in_quad_value = pytweening.easeInQuad(0.5)
print(f"EaseInQuad tween at 0.5: {ease_in_quad_value}")
# Example of interpolating a value from start to end using a tweening function
start_val = 0
end_val = 100
progress = 0.75 # 75% of the animation progress
tweened_progress = pytweening.easeInOutSine(progress)
interpolated_value = start_val + (end_val - start_val) * tweened_progress
print(f"Interpolated value at {progress} progress (easeInOutSine): {interpolated_value}")