Skip to content

Animated props

Anim<T> is a fixed value or a timeline! stored once in the video; ui.sample(&anim) reads it at the current time.

use fframes::animation::KeyFramesAnimation;
use fframes_kit::prelude::*;
struct Pulse {
radius: KeyFramesAnimation<f32>,
}
impl Pulse {
fn new() -> Self {
Self { radius: timeline!(at 0.0 => 1.0, animate 40.0_f32 => 80.0, Easing::EaseInOut) }
}
fn draw<'a>(&'a self, ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> {
let radius: Anim<'a, f32> = (&self.radius).into();
let fixed: Anim<'a, f32> = 20.0.into();
let (r, small) = (ui.sample(&radius), ui.sample(&fixed));
svgr!(<g><circle cx="200" cy="200" r={r} /><circle cx="400" cy="200" r={small} /></g>)
}
}