Skip to main content

Timeline

Struct Timeline 

Source
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

Source

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

Source

pub fn new(width: u32, height: u32, background: Color, fps: f64) -> Self

An empty timeline with render parameters: frame size, background and frame rate. These parameters are set once here and then used by the frame and render methods — there is no need to pass them to the render itself anymore.

Source

pub fn pause(&self, seconds: f64) -> &Self

Appends a pause of seconds seconds to the end of the timeline.

Source

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).

Source

pub fn sequence(&self, items: impl IntoIterator<Item = Action>) -> &Self

Appends a block of sequential actions (with no gaps).

Source

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.

Source

pub fn shapes(&self) -> Vec<Shape>

The registered root shapes (clones of the Rc handles).

Source

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).

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.