Struct DefaultAnimatorF64Quadratic

Source
pub struct DefaultAnimatorF64Quadratic { /* private fields */ }

Implementations§

Source§

impl DefaultAnimatorF64Quadratic

Source

pub fn new(value: f64, speed: f64) -> Self

Examples found in repository?
examples/default_animator_f64_quadratic.rs (line 7)
5fn main() {
6    // start at 0.5 with a speed factor of 2.
7    let mut animator = DefaultAnimatorF64Quadratic::new(0.5, 2.0);
8    // smoothly transition from 0.5 to 2
9    animator.set_target(2.0, Instant::now());
10    loop {
11        // repeatedly get the animator's current value and print it
12        let val = animator.get_value(Instant::now());
13        let count = (50.0 * val) as _;
14        eprintln!(
15            "val: {val:.2} | {}{} |",
16            "=".repeat(count),
17            " ".repeat(100 - count)
18        );
19        // once we reach 1, go to 0 instead. this simulates a user interrupting our animation.
20        if val > 1.0 {
21            animator.set_target(0.0, Instant::now());
22        }
23        // once we reach 0, exit
24        if val == 0.0 {
25            break;
26        }
27        std::thread::sleep(Duration::from_millis(50));
28    }
29}
Source

pub fn target(&self) -> f64

Trait Implementations§

Source§

impl Animator for DefaultAnimatorF64Quadratic

Source§

type Value = f64

Source§

type Time = Instant

Source§

fn get_value(&self, time: Self::Time) -> Self::Value

Source§

fn set_target(&mut self, target: Self::Value, time: Self::Time)

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.