Skip to main content

PyTweening

A collection of tweening (aka easing) functions implemented in Python. You can learn more about it in this blog post: https://inventwithpython.com/blog/2024/02/20/make-lively-movement-animation-with-pytweenings-tweening-functions/ and in the Nordic Game Jam talk by Martin Jonasson and Petri Purho at https://youtu.be/Fy0aCDmgnxg?si=8pgITaxjJSKFyBuB&t=159

Example Usage

All tweening functions are passed an argument of a float from 0.0 (the beginning of the path) to 1.0 (the end of the path) of the tween:

>>> pytweening.linear(0.5)
0.5
>>> pytweening.linear(0.75)
0.75
>>> pytweening.linear(1.0)
1.0
>>> pytweening.easeInQuad(0.5)
0.25
>>> pytweening.easeInQuad(0.75)
0.5625
>>> pytweening.easeInQuad(1.0)
1.0
>>> pytweening.easeInOutSine(0.75)
0.8535533905932737
>>> pytweening.easeInOutSine(1.0)
1.0

The getLine() function also provides a Bresenham line algorithm implementation:

>>> pytweening.getLine(0, 0, 5, 10)
[(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), (4, 8), (4, 9), (5, 10)]

The getLinePoint() function finds (interpolates) a point on the given line (even if it extends before or past the start or end points):

>>> getLinePoint(0, 0, 5, 10, 0.0)
(0.0, 0.0)
>>> getLinePoint(0, 0, 5, 10, 0.25)
(1.25, 2.5)
>>> getLinePoint(0, 0, 5, 10, 0.5)
(2.5, 5.0)
>>> getLinePoint(0, 0, 5, 10, 0.75)
(3.75, 7.5)
>>> getLinePoint(0, 0, 5, 10, 1.0)
(5.0, 10.0)

PyTweening also provides iterators to get the XY coordinates in a for loop between two points (though some floating-point rounding errors naturally occur):

>>> import pytweening
>>> for x, y in pytweening.iterLinear(0, 0, 100, 150, 0.1): print(x, y)
...
0.0 0.0
10.0 15.0
20.0 30.0
30.000000000000004 45.00000000000001
40.0 60.0
50.0 75.0
60.0 90.0
70.0 105.0
80.0 119.99999999999999
89.99999999999999 135.0
100.0 150.0
>>> for x, y in pytweening.iterEaseOutQuad(0, 0, 100, 150, 0.1): print(x, y)
...
0.0 0.0
19.0 28.5
36.00000000000001 54.00000000000001
51.0 76.5
64.00000000000001 96.00000000000001
75.0 112.5
84.0 126.0
90.99999999999999 136.5
96.00000000000001 144.0
99.0 148.5
100.0 150.0

Tweens

pytweening.linear()

pytweening.linear()

pytweening.easeInQuad()

pytweening.easeInQuad()

pytweening.easeOutQuad()

pytweening.easeOutQuad()

pytweening.easeInOutQuad()

pytweening.easeInOutQuad()

pytweening.easeInCubic()

pytweening.easeInCubic()

pytweening.easeOutCubic()

pytweening.easeOutCubic()

pytweening.easeInOutCubic()

pytweening.easeInOutCubic()

pytweening.easeInQuart()

pytweening.easeInQuart()

pytweening.easeOutQuart()

pytweening.easeOutQuart()

pytweening.easeInOutQuart()

pytweening.easeInOutQuart()

pytweening.easeInQuint()

pytweening.easeInQuint()

pytweening.easeOutQuint()

pytweening.easeOutQuint()

pytweening.easeInOutQuint()

pytweening.easeInOutQuint()

pytweening.easeInSine()

pytweening.easeInSine()

pytweening.easeOutSine()

pytweening.easeOutSine()

pytweening.easeInOutSine()

pytweening.easeInOutSine()

pytweening.easeInExpo()

pytweening.easeInExpo()

pytweening.easeOutExpo()

pytweening.easeOutExpo()

pytweening.easeInOutExpo()

pytweening.easeInOutExpo()

pytweening.easeInCirc()

pytweening.easeInCirc()

pytweening.easeOutCirc()

pytweening.easeOutCirc()

pytweening.easeInOutCirc()

pytweening.easeInOutCirc()

pytweening.easeInElastic()

pytweening.easeInElastic()

pytweening.easeOutElastic()

pytweening.easeOutElastic()

pytweening.easeInOutElastic()

pytweening.easeInOutElastic()

pytweening.easeInBack()

pytweening.easeInBack()

pytweening.easeOutBack()

pytweening.easeOutBack()

pytweening.easeInOutBack()

pytweening.easeInOutBack()

pytweening.easeInBounce()

pytweening.easeInBounce()

pytweening.easeOutBounce()

pytweening.easeOutBounce()

pytweening.easeInOutBounce()

pytweening.easeInOutBounce()

pytweening.easeInPoly() (default degree of 2)

pytweening.easeInPoly()

pytweening.easeOutPoly() (default degree of 2)

pytweening.easeOutPoly()

pytweening.easeInOutPoly() (default degree of 2)

pytweening.easeInOutPoly()

Support

If you find this project helpful and would like to support its development, consider donating to its creator on Patreon.

Metadata

Release files for hanzo-pytweening 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hanzo-pytweening 1.2.0
File Size Uploaded Provenance
hanzo_pytweening-1.2.0.tar.gz 19.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hanzo-pytweening 1.2.0
File Interpreter ABI Platform
hanzo_pytweening-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / hanzo_pytweening-1.2.0.tar.gz

Download URL hanzo_pytweening-1.2.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2481221841983677c2eb6cec15a99dc97fae9b6ada3951e3b56503a59d6c8dfd
BLAKE2b-256 checksum
How to use checksums
e9e137ebbdf7ce0cf1147b792729a91389aacd750212d918dae41e287c39c835
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release files / hanzo_pytweening-1.2.0-py3-none-any.whl

Download URL hanzo_pytweening-1.2.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
214dd7581e3e5e2c1905cf8cd5d78ec74a02e3de69c55eb6f67a833ff0ccbe29
BLAKE2b-256 checksum
How to use checksums
85d09242be550762667defa859884ed16d2f4d62c39f330c587b491794c76f29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Security for hanzo-pytweening 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page