pub struct Timeline { /* private fields */ }Expand description
An animation timeline: a top-level sequence of actions plus references to the shapes to draw.
This is a cheap shared handle (Rc) to [TimelineState]: interior mutability
lets you add actions and shapes via a shared reference — the timeline does not
need to be held as mut. This is consistent with the library’s philosophy:
shapes and signals are also shared and mutated via Rc<RefCell<…>>.
A shape registered via Shape::on remembers its timeline, so an animation
built from it can be added by simply writing it as an expression:
title.content("Hi").smooth(0.5, Easing::CubicInOut); — it appends itself to
the end of the timeline. Wrapping a single animation in sequence is no
longer needed; parallel/sequence/cascade are left for grouping
several actions.
Implementations§
Source§impl Timeline
impl Timeline
Sourcepub fn render(&self, dir: impl AsRef<Path>) -> Result<usize>
pub fn render(&self, dir: impl AsRef<Path>) -> Result<usize>
Renders the whole animation and saves the PNG frames into the dir directory.
The directory (and its parents) is created if needed. Frames are numbered
from one: 000001.png, 000002.png, … Returns the number of frames
written. The frame size, background and frame rate are taken from
Timeline::new.
To save into outputs/<scene> next to the scene file, it is more
convenient to call the render! macro — it fills in the
directory itself:
let tl = Timeline::new(480, 240, Color::from_rgba8(20, 20, 24, 255), 30.0);
// Next to this .rs file: outputs/demo/000001.png …
render!(tl, "demo").unwrap();
// Or a directory of your own directly:
tl.render("D:/render/demo").unwrap();Source§impl Timeline
impl Timeline
Sourcepub fn pause(&self, seconds: f64) -> &Self
pub fn pause(&self, seconds: f64) -> &Self
Appends a pause of seconds seconds to the end of the timeline.
Sourcepub fn parallel(&self, items: impl IntoIterator<Item = Action>) -> &Self
pub fn parallel(&self, items: impl IntoIterator<Item = Action>) -> &Self
Appends a block of simultaneous actions (the duration is the maximum of the nested ones).
Sourcepub fn sequence(&self, items: impl IntoIterator<Item = Action>) -> &Self
pub fn sequence(&self, items: impl IntoIterator<Item = Action>) -> &Self
Appends a block of sequential actions (with no gaps).
Sourcepub fn cascade(
&self,
items: impl IntoIterator<Item = Action>,
gap: f64,
) -> &Self
pub fn cascade( &self, items: impl IntoIterator<Item = Action>, gap: f64, ) -> &Self
Appends a cascade of animations: a sequence with a gap-second pause
between neighbors. Handy for a “wave” effect — add here the animations that
should start one after another at an equal interval.
Sourcepub fn duration(&self) -> f64
pub fn duration(&self) -> f64
The full duration of the timeline in seconds. A pure computation over the action tree — it does not touch the tweens’ state (unlike sampling).
Sourcepub fn seek(&self, t: f64)
pub fn seek(&self, t: f64)
Brings all participating signals to their state at the moment in time t.
Sampling is deterministic: first all values are reset to their baseline, then tweens are applied in start order — so tweens over one signal correctly “pick up” the previous value.
Sourcepub fn frame(&self, t: f64) -> Pixmap
pub fn frame(&self, t: f64) -> Pixmap
Renders a single frame at the moment in time t with the size and
background set in Timeline::new.