Module animation

Module animation 

Source
Expand description

Animation export system for ruviz

This module provides animation recording and video export capabilities, modeled after Makie.jl’s proven animation architecture.

§Features

  • Tick-based timing: Deterministic frame timing with Tick struct
  • Macro-based recording: record! for frame count, duration, and config-driven capture
  • GIF export: deterministic frame capture and GIF encoding
  • Observable integration: Reactive animations with AnimatedObservable
  • Smooth transitions: Easing functions and plot morphing
  • Compatibility wrappers: Deprecated record_* helpers remain available for older code
use ruviz::prelude::*;
use ruviz::record;

// Record with frame count and tick interpolation helpers
record!("bounce.gif", 60, |t| {
    let y = t.ease_over(easing::ease_out_bounce, 100.0, 0.0, 2.0);
    Plot::new().scatter(&[0.0], &[y])
})?;

// Or use duration syntax
record!("wave.gif", 2 secs, |t| {
    let x = t.lerp_over(0.0, 10.0, 2.0);
    Plot::new().line(&[0.0, x], &[0.0, x])
})?;

§Animation Builder API

For multi-value animations with custom easing:

use ruviz::animation::{Animation, easing};

Animation::build()
    .value("x", 0.0).to(100.0).duration_secs(2.0)
    .value("y", 50.0).to(0.0).ease(easing::ease_out_bounce)
    .record("output.gif", |values, tick| {
        Plot::new().scatter(&[values["x"]], &[values["y"]])
    })?;

§Deprecated Compatibility API

use ruviz::prelude::*;
use ruviz::animation::record;

let x: Vec<f64> = (0..100).map(|i| i as f64 * 0.1).collect();

record("wave.gif", 0..60, |frame, tick| {
    let phase = tick.time * 2.0 * std::f64::consts::PI;
    let y: Vec<f64> = x.iter().map(|&xi| (xi + phase).sin()).collect();
    #[allow(deprecated)]
    Plot::new()
        .line(&x, &y)
        .end_series()
        .title(format!("t = {:.2}s", tick.time))
}).unwrap();

The record() and record_simple() helpers are deprecated in favor of record! but remain available for older callers.

§Feature Flags

  • animation - Core animation system with GIF export
  • animation-video - compatibility alias for animation; AV1 video is not currently available

Re-exports§

pub use encoders::Codec;
pub use encoders::Encoder;
pub use encoders::Quality;
pub use crate::data::signal;
pub use crate::data::signal::Signal;

Modules§

easing
Standard easing functions for smooth animations
encoders
Video and animation encoders

Structs§

AnimatedObservable
An observable value that can animate smoothly between states
Animation
Completed animation ready for recording
AnimationBuilder
Builder for creating multi-value animations
AnimationGroup
A collection of animated observables that can be ticked together
AnimationValues
Runtime access to animated values during recording
FrameCapture
Captures rendered frames from plots
RecordConfig
Configuration for animation recording
Tick
Animation timing context for each frame
TickGenerator
Generates ticks at a fixed framerate
VideoConfig
Configuration for video output
VideoStream
Buffers frames and streams them to an encoder

Enums§

TickState
State of the current tick

Traits§

DurationExt
Extension trait for ergonomic duration creation
Interpolate
Trait for types that can be interpolated between two values
IntoFrameCount
Trait for types that can specify animation duration/frame count
Tickable
Trait for types that can be ticked for animation

Functions§

recordDeprecated
Record an animation by iterating over frames
record_animatedDeprecated
Record an animation driven by AnimatedObservable changes
record_animated_with_configDeprecated
Record animated observables with explicit configuration
record_durationDeprecated
Record an animation for a specific duration
record_duration_with_configDeprecated
Record an animation with duration and explicit config
record_plot
Record a pre-built plot to an animation file.
record_plot_with_config
Record a reactive plot with explicit configuration.
record_simpleDeprecated
Simplified animation recording with minimal boilerplate
record_simple_with_configDeprecated
Simplified animation recording with configuration
record_with_configDeprecated
Record an animation with explicit configuration