Skip to main content

A collection of tweening / easing functions.

Project description

PyTweening

A collection of tweening / easing functions implemented in Python. The tweening functions are passed the “time elapsed” value between 0.0 (start time) and 1.0 (end time) and return a “distance traveled” value between 0.0 (start point) and 1.0 (end point). The returned value could be greater than 1.0 for tweens that go past the end point, such as the elastic tween.

See the graphs in this Excel spreadsheet to see the behavior of the ease in, ease out, and ease in-out tweens: https://github.com/asweigart/pytweening/blob/master/tests/graphs.xlsx

And also here: https://i.imgur.com/KYaNM6b.png

Example Usage

All tweening / easing functions are passed an argument of a float from 0.0 (for the beginning) to 1.0 (for the end) 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.5)
0.49999999999999994
>>> 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 a point on the provided 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyTweening-1.0.0.zip (13.6 kB view details)

Uploaded Source

File details

Details for the file PyTweening-1.0.0.zip.

File metadata

  • Download URL: PyTweening-1.0.0.zip
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyTweening-1.0.0.zip
Algorithm Hash digest
SHA256 c8ac942cc1bdb32772e7f6e6b2d7eeb79d795c23519fde74bd5ee203fb7c2730
MD5 701b6e3d56b55151d5f07b56d59e950e
BLAKE2b-256 d282102e2ce5d86f5555419ce90af92043d260d9ca16aa001c75717cd1086c61

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page