ZOCallable is a library defining multiple functions f : [0, 1] -> R, and satisfying the condition f(0) = 0 and f(1) = 1. They can be used as transitions.
Project description
ZOCallable
ZOCallable is a python library providing several functions mapping a float from 0 to 1 into a float from 0 to 1, with f(0) = 0 and f(1) = 1, with some tools and type hints for validation. ZO stands for Zero-One
ZOCallables and ZOZOCallables
The package ZOCallable provides two classes to be used for validation and type hinting: ZOCallable and ZOZOCallable.
ZOCallableis used to represent any function $f$ satifying $f: [0, 1] \mapsto \mathbb{R} \text{ and } f(0) = 0 \text{ and } f(1) = 1$. The functionverify_ZOCallablecan be called on any function to verify if it satisfies the conditions, (as well asisinstance(func, ZOCallable)).ZOCallablecan also be used as type hinting.ZOZOCallableis a subclass ofZOCallable, the function must satisfy the same conditions and satifsy $f: [0, 1] \mapsto [0, 1]$. The functionverify_ZOCallablecan be called on any function to verify if it satifies the conditions, (as well asisinstance(func, ZOZOCallable)).ZOZOCallablecan also be used as type hinting.
Two other functions are provided in the package, one is normalize_ZOCallable, use to create a function that would satisfy the conditions from another, and vectorize_ZOCallable used to return a numpy vectorized function satisfying the conditions.
Functions
On top of these functions, some ZOCallables and ZOZOCallables are already implemented in the library.
Most of these functions are called something_in, something_out or something_in_out. In most cases, -_in functions are convex, -_out functions are convace, and -_in_out are convex before x = 0.5 and concave after. They can all be found in the ZOCallable.functions module.
Basic functions
Some basic ZOZOCallables are:
linear(the identity function),square_in,square_outandsquare_in_outare based on quadratic equationspower_in(n),power_out(n)andpower_in_out(n)are generalizations based on polynomial equations of degree n.root_inandroot_outare based on the square root.exp_inandexp_outare based on the exponential function.jump(n)are stairs functions with n jumps.
cubic bezier curves
The cubic bezier curves have been implemented in order to mimic the capabilities of CSS.
The function cubic_bezier(x1, y1, x2, y2) allow defining ZOCallables based on cubic bezier curves. Four functions have already been implemnted:
easeease_inease_outease_in_out
Advanced functions
Some more advanced functions are also defined:
sin_in,sin_outandsin_in_outare based on sinusoidal functionscirculare_in,circular_outandcirculare_in_outare based on circleselastic_in,elastic_out,elastic_in_out,back_in,back_out,back_in_out,bounce_in(n),bounce_out(n)which are more complex non-monotonous functions. (see example)
Example
You can use the ZOCallable and ZOZOCallable for type hints of your own functions for example:
from ZOCallable import ZOZOCallable
def non_linear_gradient(points: int, func: ZOZOCallable):
if not verify_ZOZOCallable(func, test_vectorisation=True):
raise ValueError("The provided function isn't a ZOZOCallable")
return func(np.linspace(0, 1, points))
Here, lambda x:x**2 or ZOCallable.functions.ease_in will satisfy the conditions and so be accepted, while lambda x:2*x would raise a ValueError
You can also use them for transitions or moves
from ZOCallable.functions import bounce_out
class FallingBall:
def __init__(self, height: float, bounces: int, duration: int)
self.z = height
self.height = height
self.trajectory = bounce_out(bounces)
self.duration = duration
self.time = 0
def udpate(self, dt):
self.time += dt
self.z = self.trajectory(self.time/self.duration)*self.height
def get_altitude(self):
return self.z
bounce_out(n) being a non-monotonous ZOZOCallable, the fall of the ball here would follow the curve of the bounce_out.
A precomputed trajectory is faster and easier for modelization.
Demonstration
Some of the functions have been plotted and are shown below.
Contributing
Any feedback optimization or new function proposal is welcome.
License
This library is under a GNU License.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zocallable-1.0.2.tar.gz.
File metadata
- Download URL: zocallable-1.0.2.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90d2b902701b892b05b0ffbbaccc630d1067a72595880d2c0f36d9f7e3fd8cf2
|
|
| MD5 |
eb34d735dc599e38a4b0a720de55d064
|
|
| BLAKE2b-256 |
b06a49a7b0184239fa17fc950466423787491f4c26d2bb4f9e0a7baa2ebac569
|
File details
Details for the file ZOCallable-1.0.2-py3-none-any.whl.
File metadata
- Download URL: ZOCallable-1.0.2-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9902e4e7d3230cfccdd9c36068668cdfe2dafb84e389220b0502b9a2d90e0f1
|
|
| MD5 |
22ccc1cc42a8c6709c0c6673be1b3963
|
|
| BLAKE2b-256 |
3d8a1ff8f5956c7a8d280a80d8fd195759f2926c70144aa2f95c8b8468c1a0ff
|