Tweeny, an interpolation library: ten years later


Hello!

Almost ten years ago I announced Tweeny on this forum:

Today I’m releasing Tweeny 4.0.0, a rewrite of that library. Still header-only, no external dependencies, C++17. Fluent builder API, 30+ easings, multi-point keyframes, events, plus seek / jump / peek for timeline control.

Tweeny is a header-only C++ library that interpolates values over time. You give it a start, an end, a duration in frames, and optionally an easing function. Each frame you call step, and you get the next values to apply to your objects.

That is useful with SDL because your loop already runs once per frame. Tweeny does not draw anything and does not own a clock. It only produces numbers (or other arithmetic types) you write into positions, sizes, angles, colors, sprite indices, and so on. Typical uses: fade a menu in by alpha, slide a panel on screen, scale a focused button, ease a camera, advance sprite frames, rotate something into place.

One tween can carry several values at once, including mixed types (for example sprite frame, x/y position, and rotation). You can also chain keyframes when the motion has more than two points.

Example: interpolate hello to world character by character over 50 frames:

#include <tweeny/tweeny.h>

auto helloworld = tweeny::from('h', 'e', 'l', 'l', 'o')
                    .to('w', 'o', 'r', 'l', 'd')
                    .during(50U)
                    .build();

for (int i = 0; i < 50; i++) {
    auto [w, o, r, l, d] = helloworld.step(1);
    printf("%c%c%c%c%c\n", w, o, r, l, d);
}

Links:

Leonardo


2 Likes

You can embed videos in posts here. It would be neat to see some of the interpolations in action.