record

Function record 

Source
pub fn record<P, I, F, R>(path: P, frames: I, frame_fn: F) -> Result<()>
where P: AsRef<Path>, I: IntoIterator, F: FnMut(I::Item, &Tick) -> R, R: Into<Plot>,
👎Deprecated since 0.1.0: Use the record! macro instead: record!(path, frames, |t| plot)
Expand description

Record an animation by iterating over frames

This is the primary API for creating animations. It iterates over the provided frames, calling the frame function for each to generate a plot, then captures and encodes each frame.

§Type Parameters

  • P - Output path type (implements AsRef<Path>)
  • I - Iterator type for frame data
  • F - Frame function type

§Arguments

  • path - Output file path (format detected from extension)
  • frames - Iterator of frame data (e.g., 0..60 for 60 frames)
  • frame_fn - Function that produces a Plot for each frame

§Example

ⓘ
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!("Frame {}", frame))
}).unwrap();