__
___ ____ _________ / /_
/ _ \/ __ `/ ___/ _ \ / __ \
/ __/ /_/ (__ ) __/ / / / /
\___/\__,_/____/\___(_)_/ /_/
A single-header C library of easing functions.
- Single header, no build step. Drop
ease.hinto your project. - 10 easing families, each with
in,out, andin_outvariants. 30 functions total. - Float and double precision, selectable independently via
EASE_FLOAT/EASE_DOUBLE. - Works as a normal header (
externdeclarations) or fully inlined into one translation unit viaEASE_STATIC. - Optional
EASE_NO_PREFIXto drop theease_prefix if you've namespaced the include some other way. - Plain C99, compiles clean under
-Wall -Wextra -Wpedantic -Werror. Also compiles as C++. - MIT licensed.
Copy ease.h into your project. In exactly one .c or .cpp file, define EASE_IMPLEMENTATION before including it:
#define EASE_IMPLEMENTATION
#include "ease.h"Every other file that needs the declarations just includes it normally:
#include "ease.h"A minimal example, animating a value over 60 frames using ease_in_out_cubic_f:
#define EASE_IMPLEMENTATION
#include "ease.h"
#include <stdio.h>
int main(void)
{
const int total_frames = 60;
for (int frame = 0; frame <= total_frames; frame++)
{
float t = (float)frame / (float)total_frames;
float eased = ease_in_out_cubic_f(t);
printf("frame %2d: t=%.3f eased=%.3f\n", frame, t, eased);
}
return 0;
}On Linux/glibc, link against libm:
gcc -std=c99 -o demo demo.c -lm
Every function takes a single progress value x, typically in [0, 1], and returns the eased progress. back and elastic intentionally overshoot outside [0, 1] partway through the curve, everything else stays within [0, 1].
Each row lists the float variant; the double variant has the same name with _d instead of _f.
| Function | Family | Notes |
|---|---|---|
ease_in_sine_f |
Sine | |
ease_out_sine_f |
Sine | |
ease_in_out_sine_f |
Sine | |
ease_in_quad_f |
Quad | |
ease_out_quad_f |
Quad | |
ease_in_out_quad_f |
Quad | |
ease_in_cubic_f |
Cubic | |
ease_out_cubic_f |
Cubic | |
ease_in_out_cubic_f |
Cubic | |
ease_in_quart_f |
Quart | |
ease_out_quart_f |
Quart | |
ease_in_out_quart_f |
Quart | |
ease_in_quint_f |
Quint | |
ease_out_quint_f |
Quint | |
ease_in_out_quint_f |
Quint | |
ease_in_expo_f |
Expo | |
ease_out_expo_f |
Expo | |
ease_in_out_expo_f |
Expo | |
ease_in_circ_f |
Circ | |
ease_out_circ_f |
Circ | |
ease_in_out_circ_f |
Circ | |
ease_in_back_f |
Back | overshoots |
ease_out_back_f |
Back | overshoots |
ease_in_out_back_f |
Back | overshoots |
ease_in_elastic_f |
Elastic | overshoots |
ease_out_elastic_f |
Elastic | overshoots |
ease_in_out_elastic_f |
Elastic | overshoots |
ease_in_bounce_f |
Bounce | |
ease_out_bounce_f |
Bounce | |
ease_in_out_bounce_f |
Bounce |
Define these before including ease.h. If you include the header in more than one translation unit, define the same macros in each one.
| Macro | Effect |
|---|---|
EASE_IMPLEMENTATION |
Includes function definitions, not just declarations. Define this in exactly one .c/.cpp file. |
EASE_FLOAT |
Builds only the _f (float) functions. |
EASE_DOUBLE |
Builds only the _d (double) functions. |
EASE_STATIC |
Marks every function static instead of extern. Use this to include the header with EASE_IMPLEMENTATION directly in a single .c file without multiple-definition errors. Every including translation unit gets its own private copy. |
EASE_NO_PREFIX |
Drops the ease_ prefix from every function name, e.g. in_out_cubic_f instead of ease_in_out_cubic_f. Watch for name collisions with other libraries if you use this. |
If neither EASE_FLOAT nor EASE_DOUBLE is defined, both are built. This is the default.
ease_<in|out|in_out>_<family>_<f|d>(x)
in/out/in_outis the direction of the curve.familyis one ofsine,quad,cubic,quart,quint,expo,circ,back,elastic,bounce.f/dis float or double precision.
With EASE_NO_PREFIX defined, the leading ease_ is dropped and the pattern becomes <in|out|in_out>_<family>_<f|d>(x).
ease.h has no dependencies beyond <math.h>. It compiles clean under both C and C++ with strict warnings enabled:
gcc -std=c99 -Wall -Wextra -Wpedantic -Werror -c test.c -lm
g++ -std=c++17 -Wall -Wextra -Wpedantic -Werror -c test.cpp -lm
Every function has been checked against a reference implementation of Penner's easing equations, confirming f(0) == 0 and f(1) == 1 for all 30 functions in both precisions, plus midpoint values matched to several decimal places.
The easing equations implemented here are standard, widely-published formulas originating from Robert Penner's easing equations, catalogued today at easings.net, created by Andrey Sitnik and Ivan Solovev.
MIT. See LICENSE.