Expand description
dinamika-core — a declarative library for building animations on top of
the raster renderer dinamika_cpu.
It consists of three parts:
- Shapes (
Shape) — scene nodes with flex layout (direction, justify, align, gap, padding, children) and signal-backed properties (background, sizes, corner radius, opacity, rotation). Rectangle, circle, layout container and text (Shape::text) are supported, with CSS-like properties (font, font size, color, alignment, line height, letter spacing). - Signals (
Signal,Computed) — reactive values in the spirit of Motion Canvas: read, written and animated. - Timeline (
Timeline) — composition of animations over time: pause (Timeline::pause), parallel (Timeline::parallel) and sequence (Timeline::sequence/Timeline::cascade). Shapes are registered on the timeline viaShape::on, and properties are animated with the same shape setter methods (x,background,rotation, …) — by appending.over(duration, easing).
§Example
use dinamika_core::*;
// The timeline is created first (interior mutability — no `mut`).
let tl = Timeline::new(320, 160, Color::from_rgba8(20, 20, 24, 255), 30.0);
// Scene: a row container with two squares, registered on the timeline.
let a = Shape::rect().background(Color::from_rgba8(229, 192, 123, 255)).size(60.0, 60.0);
let b = Shape::rect().background(Color::from_rgba8(152, 195, 121, 255)).size(60.0, 60.0);
let _row = Shape::rect()
.at(20.0, 20.0)
.background(Color::from_rgba8(40, 44, 52, 255))
.radius(12.0)
.direction(Direction::Row)
.gap(20.0)
.padding(20.0)
.align(Align::Center)
.child(a.clone())
.child(b.clone())
.on(&tl);
// Move and recolor in parallel, wait, then a sequence of opacities.
tl.parallel(vec![
a.rotation(180.0).over(1.0, Easing::CubicInOut),
b.background(Color::from_rgba8(97, 175, 239, 255)).over(1.0, Easing::Linear),
]);
tl.pause(0.25);
tl.sequence(vec![
a.opacity(0.2).over(0.5, Easing::QuadOut),
b.opacity(0.2).over(0.5, Easing::QuadOut),
]);
// A single frame (RGBA, premultiplied alpha).
let frame = tl.frame(0.5);
assert_eq!(frame.width(), 320);Re-exports§
pub use dinamika_cpu as cpu;
Macros§
- render
- Renders the whole timeline animation into the
outputs/<scene>directory next to the.rsfile where the macro is called; returns astd::io::Resultcarrying only success/failure. The number of saved frames is not returned — if you need it, callTimeline::renderdirectly. - scene_
dir - Default output directory for a scene —
outputs/<scene>next to the.rsfile where the macro is called.
Structs§
- Action
- The unit of timeline composition: a tween, pause, parallel or sequence.
- Color
- A color in floating-point RGBA format in the range
0.0..=1.0, non-premultiplied alpha. - Computed
- A derived (computed) signal — read-only.
- Gradient
Stop - A gradient stop.
- Highlight
Edit - A handle of range highlighting, returned by
highlightandclear_highlight. - Linear
Gradient - A linear gradient along the segment
start–end. - Padding
- The shape’s inner padding by side.
- Padding
Tween - A handle of the
paddingproperty — likeTween, but animates all four padding sides at once.overbuilds a parallel tween. - Paint
- A fill description: the color source, blend mode and anti-aliasing.
- Palette
- A highlight palette: “token category → color”, assembled manually.
- Pixmap
- Bitmap:
width × heightRGBA pixels, premultiplied alpha. - Point
- A point (or vector) in the plane.
- Radial
Gradient - A radial gradient around a center.
- Rect
- A rectangle defined by its bounds in floating-point coordinates.
- Shape
- A scene node. This is a cheap shared handle (
Rc): a clone points to the same shape, so it can be held both in the scene tree and in the timeline. - Signal
- A reactive value, shared by reference.
- Text
Edit - A handle of a text edit, returned by the text shape’s editor methods
(
content,append,prepend,insert,rewrite). - Timeline
- An animation timeline: a top-level sequence of actions plus references to the shapes to draw.
- Transform
- A 2×3 affine transformation.
- Tween
- A handle of an animatable property, returned by its setter method.
Enums§
- Align
- Alignment along the cross axis (analogous to
align-items). - Blend
Mode - Blend mode of the source and the background.
- Direction
- The children’s layout axis (analogous to
flex-direction). - Easing
- Animation easing curve.
- Justify
- Distribution along the main axis (analogous to
justify-content). - Language
- The code shape’s highlight language. Resolves to a Sublime Text grammar from
the built-in
syntectset; an unknown grammar (orPlainText) means “no parsing” — all the code is colored with the palette’s base color. - Length
- A length along one axis: absolute in pixels, or a fraction of the parent’s
content area in percent. Passed to
widthandheight. - Shader
- A color source.
- Shape
Kind - Shape kind.
- Spread
Mode - How coordinates outside
0..=1are handled for a gradient. - Text
Align - Horizontal alignment of lines within a text block (analogous to
CSS
text-align). - TextPos
- A position in the text for the bounds of a
rewriterange.
Traits§
- Into
Children - Conversion of a
Shape::childrenargument into a list of child shapes. - Tweenable
- A type whose values can be linearly interpolated.
Functions§
- cascade
- A cascade: sequential execution of actions with a
gap-second pause between neighbors. Put inside the animations that should follow each other in a “wave”. - delay
- An action that starts after
secondsseconds. - infinite
- The position of the end of the text for the
tobound inrewrite. - line
- The position of the start of line
n(0-based) forrewrite. - parallel
- Simultaneous execution of all the actions. The duration is the maximum of the nested ones.
- pause
- A pause of the given duration (in seconds).
- render_
scene - Draws a scene of root shapes over the
background. - scene_
output_ dir - Default output directory for a scene:
<source-dir>/outputs/<scene>. - sequence
- Sequential execution one after another (with no gaps).