ease

Easing functions for more natural animation transitions, derived from Easings.net.

Types

An easing function maps a float from 0..1 into a float.

pub type Ease =
  fn(Float) -> Float

Values

pub fn back(t: Float) -> Float

Eases away from the goal before accelerating toward it.

See more info on Easings.net.

pub fn bounce(t: Float) -> Float

Eases in by “bouncing” around the start.


    1 _ ________________________________________________⣀⣀⡀
      _                                            ⢀⠤⠒⠊⠉
 0.75 _                                          ⡠⠊⠁
      _                                        ⡠⠊
  0.5 _                                      ⡠⠊
      _                                    ⢀⠔
 0.25 _                     ⢀⣀⣀⣀⣀⡀        ⠠⠂
      _                 ⣀⠤⠒⠉⠁    ⠈⠉⠒⠤⣀   ⡐⠁
    0 _ ⣀⣀⣀⣀⣀⡠⠤⠒⠒⠒⠒⠢⠤⢄⠤⠊______________⠑⢄⠔__________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn circular(t: Float) -> Float

Eases in on an elliptic arc.


    1 _ __________________________________________________⡀
      _
 0.75 _                                                 ⢀⠊
      _                                               ⢀⠔⠁
  0.5 _                                            ⣀⠤⠊⠁
      _                                       ⢀⣀⠤⠒⠉
 0.25 _                                 ⢀⣀⠤⠤⠒⠊⠁
      _                        ⣀⣀⣀⠤⠤⠔⠒⠊⠉⠁
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠤⠤⠤⠔⠒⠒⠒⠊⠉⠉⠉____________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn cubic(t: Float) -> Float

Eases in cubically.


    1 _ __________________________________________________⡀
      _                                                 ⡠⠊
 0.75 _                                              ⢀⠔⠉
      _                                           ⢀⡠⠊⠁
  0.5 _                                        ⢀⡠⠒⠁
      _                                     ⣀⠔⠊⠁
 0.25 _                                ⣀⡠⠔⠊⠉
      _                         ⣀⣀⡠⠤⠒⠊⠉
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡠⠤⠤⠤⠤⠤⠔⠒⠒⠊⠉⠉___________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn elastic(t: Float) -> Float

Eases by oscillating with increasing amplitude around the start.


    1 _ __________________________________________________⡀
      _                                                  ⠠
 0.75 _                                                  ⠄
      _                                                 ⠠
  0.5 _                                                 ⡀
      _
 0.25 _                                                ⠈
      _                                   ⢀⣀⣀⡀         ⠁
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⢄⣀⣀⣀______⣀⠤⠊⠁__⠈⠢_______⠐____
                                 ⠉⠉⠉⠉⠉⠉        ⠑⡀     ⠂
        |''''|''''|''''|''''|''''|''''|''''|''''⠐⠄'''⡈''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8⠢⣀0.9   1

See more info on Easings.net.

pub fn exponential(t: Float) -> Float

Eases in exponentially.


    1 _ __________________________________________________⡀
      _                                                  ⡐
 0.75 _                                                 ⡐
      _                                               ⢀⠌
  0.5 _                                              ⡠⠂
      _                                            ⡠⠊
 0.25 _                                         ⡠⠔⠉
      _                                   ⢀⣀⠤⠔⠒⠉
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠤⠤⠤⠤⠤⠒⠒⠒⠒⠉⠉⠁________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn join(
  ease_start: fn(Float) -> Float,
  ease_end: fn(Float) -> Float,
) -> fn(Float) -> Float

Join two easing functions.

Examples

join(back, elastic |> reverse)

Output functions graph:


                                   ⢀⠒⢄
    1 _ ___________________________⠄__⢂___⣀⠤⠤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀
      _                           ⠠    ⠑⠒⠊
 0.75 _                           ⡀
      _
  0.5 _                          ⡈
      _                        ⢀⠌
 0.25 _                       ⡠⠁
      _                    ⢀⠔⠊
    0 _ ⣀⣀⣀⣀___________⣀⡠⠤⠊⠁_______________________________
            ⠉⠉⠉⠉⠉⠒⠒⠒⠉⠉⠉
        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
pub fn join_at(
  ease_start: fn(Float) -> Float,
  ease_end: fn(Float) -> Float,
  at: Float,
) -> fn(Float) -> Float

Join two easing functions at a given point.

Examples

join(linear, bounce |> reverse, 0.25)

Output functions graph:


    1 _ __________________________⡀____________⢀⡀_____⣀⣀⣀⣀⡀
      _                          ⡐⠈⠑⠤⣀      ⢀⡠⠔⠁⠈⠉⠉⠉⠉⠉
 0.75 _                        ⢀⠌     ⠉⠒⠒⠒⠒⠉⠁
      _                       ⡠⠂
  0.5 _                     ⢀⠔
      _                   ⡠⠔⠁
 0.25 _             ⣀⣀⡠⠤⠒⠉
      _      ⢀⣀⡠⠤⠒⠊⠉
    0 _ ⣀⠤⠔⠒⠉⠁_____________________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
pub fn linear(t: Float) -> Float

Linear easing is an identity transformation, time is not skewed.


    1 _ _________________________________________________⢀⡀
      _                                            ⣀⣀⠤⠔⠒⠉⠁
 0.75 _                                      ⣀⡠⠤⠒⠊⠉
      _                               ⢀⣀⡠⠤⠒⠊⠉
  0.5 _                         ⢀⣀⠤⠔⠒⠉⠁
      _                   ⣀⣀⠤⠔⠒⠉⠁
 0.25 _             ⣀⡠⠤⠒⠊⠉
      _      ⢀⣀⡠⠤⠒⠊⠉
    0 _ ⣀⠤⠔⠒⠉⠁_____________________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
pub fn quadratic(t: Float) -> Float

Eases in quadratically.


    1 _ __________________________________________________⡀
      _                                               ⢀⡠⠔⠉
 0.75 _                                            ⣀⠤⠒⠁
      _                                        ⢀⡠⠒⠉
  0.5 _                                    ⣀⠤⠒⠊⠁
      _                               ⣀⡠⠔⠒⠉
 0.25 _                         ⢀⣀⠤⠔⠒⠉
      _                  ⣀⣀⠤⠤⠒⠒⠉⠁
    0 _ ⣀⣀⣀⣀⣀⣀⡠⠤⠤⠤⠤⠒⠒⠒⠉⠉⠉__________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn quartic(t: Float) -> Float

Eases in quartically.


    1 _ __________________________________________________⡀
      _                                                 ⢀⠊
 0.75 _                                               ⢀⠔⠁
      _                                             ⢀⠔⠁
  0.5 _                                           ⡠⠒⠁
      _                                        ⣀⠔⠊
 0.25 _                                    ⣀⠤⠒⠉
      _                              ⣀⣀⠤⠔⠒⠉
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠤⠤⠔⠒⠒⠊⠉⠉______________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn quintic(t: Float) -> Float

Eases in quintically.


    1 _ __________________________________________________⡀
      _                                                  ⠔
 0.75 _                                                ⠠⠊
      _                                              ⢀⠔⠁
  0.5 _                                            ⢀⠔⠁
      _                                          ⡠⠔⠁
 0.25 _                                      ⢀⡠⠔⠊
      _                                 ⢀⣀⠤⠔⠊⠁
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠤⠤⠔⠒⠒⠊⠉⠁__________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn reverse(ease: fn(Float) -> Float) -> fn(Float) -> Float

Inverts an easing function, so ease-in becomes ease-out and ease-out becomes ease-in.

Examples

quartic |> reverse

Output functions graph:


    1 _ ________________________________⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀
      _                    ⢀⣀⡠⠤⠤⠒⠒⠒⠉⠉⠉⠉⠉⠁
 0.75 _               ⢀⡠⠔⠒⠉⠁
      _           ⢀⡠⠔⠊⠁
  0.5 _         ⡠⠒⠁
      _      ⢀⠔⠊
 0.25 _    ⢀⠔⠁
      _  ⢀⠔⠁
    0 _ ⡠⠂_________________________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
pub fn sine(t: Float) -> Float

Eases in with a sine function.


    1 _ __________________________________________________⡀
      _                                               ⣀⠤⠒⠉
 0.75 _                                          ⢀⡠⠔⠒⠉
      _                                      ⢀⡠⠔⠊⠁
  0.5 _                                  ⣀⠤⠔⠊⠁
      _                             ⣀⡠⠔⠒⠉
 0.25 _                       ⢀⣀⠤⠔⠒⠉
      _                ⢀⣀⡠⠤⠒⠒⠉⠁
    0 _ ⣀⣀⣀⣀⣀⣀⠤⠤⠤⠤⠒⠒⠒⠉⠉⠁___________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1

See more info on Easings.net.

pub fn spring(t: Float) -> Float

Eases in like a spring around the start.


    1 _ __________________________________________________⡀
      _                                                 ⡠⠊
 0.75 _                                               ⡠⠊
      _                                             ⡠⠊
  0.5 _                                          ⣀⠔⠉
      _                                       ⢀⠤⠊
 0.25 _                                    ⣀⠤⠊⠁
      _                                ⢀⡠⠔⠊
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠤⢄⣀⣀____________⣀⡠⠔⠊⠁___________________
                       ⠉⠉⠒⠒⠢⠤⠤⠤⠒⠒⠊⠉
        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
pub fn symmetry(ease: fn(Float) -> Float) -> fn(Float) -> Float

Making an easing function symmetry by joining it to its reversed self, so ease-in becomes ease-in-out and ease-out becomes ease-out-in.

Examples

quartic |> symmetry

Output functions graph:


    1 _ _______________________________________⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀
      _                                 ⣀⠤⠔⠒⠊⠉⠉⠁
 0.75 _                              ⡠⠔⠉
      _                           ⢀⠔⠊
  0.5 _                          ⡠⠂
      _                        ⢀⠊
 0.25 _                      ⡠⠒⠁
      _                  ⢀⡠⠔⠉
    0 _ ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠒⠒⠉⠁_________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
quartic |> reverse |> symmetry

Output functions graph:


    1 _ __________________________________________________⡀
      _                                                 ⢀⠊
 0.75 _                                               ⡠⠒⠁
      _                                           ⢀⡠⠔⠉
  0.5 _               ⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⠤⠤⠤⠒⠒⠉⠁
      _        ⣀⠤⠔⠒⠊⠉⠉⠁
 0.25 _     ⡠⠔⠉
      _  ⢀⠔⠊
    0 _ ⡠⠂_________________________________________________

        |''''|''''|''''|''''|''''|''''|''''|''''|''''|''''|
        0   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9   1
Search Document