KramaFrame
A simple, generic, and flexible keyframe animation library for Rust.
KramaFrame provides a straightforward way to manage and update multiple animations, map their progress to value ranges, and apply various easing functions for smooth and dynamic transitions.
Features
- Manage multiple animations using string-based class names and numeric IDs.
- A rich set of built-in easing functions:
LinearEaseIn,EaseOut,EaseInOutSteps(n)for stepped animations- Custom
CubicBeziercurves
- Generic over time (
TRES) and progress (PRES) data types for maximum flexibility. - Easily map animation progress (from 0.0 to 1.0) to any numerical output range.
- Play animations forwards or in reverse.
- Update all active animations with a single call in your game or application loop.
Getting Started
Add kramaframe to your project's Cargo.toml:
[]
= "0.1.2"
Or, add it via the command line:
Usage
Here's a basic example of animating a value from 80 to 100 over a set duration.
use ;
Easing Functions (KeyFrameFunction)
KramaFrame uses KeyFrameFunction to control the rate of change of an animation, allowing for more natural and interesting motion.
Available Functions
KeyFrameFunction::Linear: Constant speed.KeyFrameFunction::EaseIn: Starts slow, then accelerates.KeyFrameFunction::EaseOut: Starts fast, then decelerates.KeyFrameFunction::EaseInOut: Starts and ends slow, with acceleration in the middle.KeyFrameFunction::Steps(n): Divides the animation intondiscrete, instantaneous steps.KeyFrameFunction::new_cubic_bezier_f32(x1, y1, x2, y2): Defines a custom animation curve using Cubic Bezier control points, similar to CSScubic-bezier().
Example
You can define multiple animation classes, each with its own easing function.
use ;
let mut kramaframe = default;
// Define different animation classes
kramaframe.extend_iter_classlist;
// Create instances for each animation class with a duration of 1.0
kramaframe.insert_new_id;
kramaframe.insert_new_id;
// ... and so on for the other classes
// In your update loop, you can get values for each:
kramaframe.update_progress; // ~60 FPS
let linear_val = kramaframe.get_value_byrange;
let easein_val = kramaframe.get_value_byrange;
println!;
More Examples
You can find more detailed examples in the /examples directory of the repository:
iterrange.rs: A complete, runnable version of the basic usage example.allkeyframe.rs: Demonstrates and visualizes all availableKeyFrameFunctiontypes.reverse.rs: Demonstrates how to reverse the direction of an animation instance.
License
This project is licensed under
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
TODO:
- Add more examples
-
no_stdsupport - ... can be more from commit.