dinamika-core
A declarative animation library built on top of the
dinamika-cpu raster renderer. In the spirit of
Motion Canvas: a scene of flex-laid-out shapes whose
properties are reactive signals, animated on a timeline and rendered to PNG
frames.
It consists of three parts:
- Shapes (
Shape) — scene nodes with CSS-like flex layout and signal-backed properties. - Signals (
Signal,Computed) — reactive values that can be read, written and animated. - Timeline (
Timeline) — composition of animations over time: pause, parallel and sequence/cascade.
Features
- Shapes — rectangle (
Shape::rect), circle/ellipse (Shape::circle), a backgroundless layout container (Shape::layout), text (Shape::text) and code (Shape::code). - Flex layout —
Direction,Justify,Align,gap, per-sidepadding(with CSS-like shorthands),children, and sizes as aLength(pixels or a percentage of the parent) with min/max bounds. - Animatable properties — position, size, background, corner radius,
opacity, rotation, scale, gap and padding. Each setter sets the value
immediately and returns a handle; append
.over(duration, easing)to animate. - Text — CSS-like style (font, font size, color, alignment, letter spacing, line height), content edits (spawn/typing/smoothing) and range highlighting.
- Code — the same text, but colored per-character by syntax highlighting via
a manually configured
Paletteand aLanguage(powered bysyntect). - Easing — a full set of curves (
Quad/Cubic/Quart/Sine/Expo/Back/Bounce/Elastic, each inIn/Out/InOut). - Timeline —
pause,parallel,sequenceandcascade; a registered shape's single animation can be added as a plain expression. - Output — render the whole animation to numbered PNG frames, directly or
via the
scene_dir!/render!macros.
Architecture
| Module | Purpose |
|---|---|
easing |
interpolation curves (Easing) |
signal |
reactive values (Signal, Computed, Tweenable) |
shape |
scene nodes, flex layout, text and code |
timeline |
composition of animations over time and scene sampling |
render |
two-pass flex layout and rasterization onto a Pixmap |
output |
saving frames to PNG (render, scene_dir!/render!) |
The renderer is re-exported as dinamika_core::cpu, with frequently used types
(Color, Pixmap, Paint, Transform, gradients, …) lifted to the crate root.
Example
use *;
// The timeline is created first (interior mutability — no `mut`).
let tl = new;
// Scene: a row container with two squares, registered on the timeline.
let a = rect.background.size;
let b = rect.background.size;
let _row = rect
.at
.background
.radius
.direction
.gap
.padding
.align
.child
.child
.on;
// Move and recolor in parallel, wait, then a sequence of opacities.
tl.parallel;
tl.pause;
tl.sequence;
// A single frame (RGBA, premultiplied alpha)…
let frame = tl.frame;
assert_eq!;
// …or render the whole animation to PNG frames.
tl.render.unwrap;
Set a value or animate it
Each animatable property has one setter that takes a value. It applies the
value immediately and returns a lightweight handle that dereferences back into
the Shape, so the builder chain keeps flowing. The same setter, with
.over(...), builds a tween for the timeline:
use *;
let card = rect.at.size;
// Set now:
card.background.radius;
// Animate (on the timeline):
let _move = card.x.over;
Code with syntax highlighting
use *;
let bytes = read.unwrap;
let snippet = code
.font
.font_size
.language
.palette;
The demonstration scene can be rendered with the command:
cargo run -p dinamika