Robert Penner's easings functions in python
Project description
Robert Penner's Easing Functions
There are a plethora of versions available of these, many of which provide an object oriented interface, while most of the original easing functions could be simple inline expressions.
This library takes the purely functional approach. No class instantiation, just a function call.
See https://easings.net for a good visualisation of these to chose the right one.
Module contents
With the exception of null
, in_expx
and out_expx
, this is a pure python
port of "Penner's Easing Functions", based on the js code from
https://easings.net where you can also see a catalog of them in action to
chose the right one.
The following functions are included:
in_back out_back in_out_back
in_bounce out_bounce in_out_bounce
in_circ out_circ in_out_circ
in_cubic out_cubic in_out_cubic
in_elastic out_elastic in_out_elastic
in_expo out_expo in_out_expo
in_quad out_quad in_out_quad
in_quart out_quart in_out_quart
in_quint out_quint in_out_quint
in_sine out_sine in_out_sine
Additionally, I added a 'null' function, so easing can be disabled without
changing the interface in the application. It's basically a nop
.
null(t) -> t
In case you want to control the easing function by user input, the easings
dictionary provides a map from function names to functions, e.g.
eased = rpeasings.easings['out_elastic']
To use any of the included functions, create a t
(for 'time') value in the
range 0-1 from your required range (e.g. t = current / max
).
Putting this t
into most(!) easing function, will give you a new 'eased'
value in the range 0-1.
Note: the following functions over-/undershoot:
`in_back` `out_back` `in_out_back`
`in_elastic` `out_elastic` `in_out_elastic`
Additionally, you can then put that eased value as input into a lerp
function to add dynamics to an otherwise linear range.
Have fun, once you started using one, you'll probably find usecases for them everywhere in your game...
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
Built Distribution
File details
Details for the file rpeasings-0.0.3.tar.gz
.
File metadata
- Download URL: rpeasings-0.0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34c32e08e7445c37dbfcd89bfcbcf206458b03cad260b139f642a9afa95e887 |
|
MD5 | 87226f9eb54e99db86170264448b182c |
|
BLAKE2b-256 | d45bbfe058831b2d2ba74bd74408c1f35112264c3ab87233908e5ae71df97e12 |
File details
Details for the file rpeasings-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: rpeasings-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27ede7929fc6d5dc5169fc5249acc773e843dc60e70f8c4809f898ffa72e5ced |
|
MD5 | b28eee40e602d5bac84074c5f3f45007 |
|
BLAKE2b-256 | 47b5e7b614af1fcf2609226fad7dd080d1ad749d6322449158d33ca7c8b0971a |