[−][src]Struct gravitas::Gravity
a position under the influence of gravity (or any other constant acceleration), as defined by Newton's 2nd Law: F = ma
.
Newton's 2nd law, F = ma
, integrates to x' = x + v * t + 0.5 * a * t * t
, which is what this simulation uses to compute a position.
This simulation is nice for objects that are falling, or have to overcome gravity in some way.
- gravity combined with a spring simulation to make bouncy dialog boxes: Gravitas JavaScript bouncy dialogs.
- gravity used to make a lock screen, which must be dragged upwards to unlock: Gravitas JavaScript lock screen.
Methods
impl Gravity
[src]
pub fn new(a: f32) -> Gravity
[src]
Create a new gravity siulation with the given acceleration. A value of 500 * 9.8 (so 500px corresponds to 1 meter) is normally a good starting point.
pub fn set(&mut self, x: f32, v: f32)
[src]
Set the initial position and velocity (in pixels per second) of the gravity simulation.
Trait Implementations
impl Simulation for Gravity
[src]
fn x(&self, time: f32) -> f32
[src]
fn dx(&self, time: f32) -> f32
[src]
fn is_done(&self, time: f32) -> bool
[src]
impl Clone for Gravity
[src]
impl Copy for Gravity
[src]
Auto Trait Implementations
impl Send for Gravity
impl Sync for Gravity
impl Unpin for Gravity
impl UnwindSafe for Gravity
impl RefUnwindSafe for Gravity
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,