@blinkk/degu
    Preparing search index...

    Function ease

    • An alias of [[mathf.lerpEase]]

      This is a general ease function that is pretty handy for animations.

      This is basically a way of saying, given my start and end values, what is the value when it's at x percent (progress) with easing.

      Under the hood, it is simply an alias of [[mathf.lerpEase]] which is essentially a regular lerp but it passes the progress value (0-1) through an easing function first.

      Using mathf.ease, you can pretty easily calculate eases for numberic values.

      Say I wanted to animate a box.x position from 0 - 100. Without specifying a easing function, you will just get linear interpolation.

      mathf.ease(0, 100, 0) ---> 0
      mathf.ease(0, 100, 0.3) ---> 30
      mathf.ease(0, 100, 0.5) ---> 50
      mathf.ease(0, 100, 0.9) ---> 90
      mathf.ease(0, 100, 1) ---> 100

      Now lets try this with easing. You can see the returned values between 0 and 1 are different than a linear ease.

      You can also combine with CubicBezier.makeEasingFunction or a catmull-roll.

      import { EASE, mathf} from '@blinkk/degu'
      mathf.ease(0, 100, 0, EASE.easeInExpo) ---> 0
      mathf.ease(0, 100, 0.3, EASE.easeInExpo) ---> 0.1953125
      mathf.ease(0, 100, 0.5, EASE.easeInExpo) ---> 3.125
      mathf.ease(0, 100, 0.9, EASE.easeInExpo) ---> 70.710678
      mathf.ease(0, 100, 1, EASE.easeInExpo) ---> 100



      import { CubicBezier, EASE, mathf} from '@blinkk/degu'
      mathf.ease(0, 100, 0.3, CubicBezier.makeEasingFunction(0, 1, 0.75, 0.9)) ---> 100

      How can I use this with animations?

      You can ease out positions, opacity etc based on "progress". Progress can be time, scroll position, mouse position etc but it needs to be normalized to a value between 0 and 1.

      See examples of this in [[RafTimer]] where there is a demo of easing an element for a set duration.

      For an exmaple where you may want to tie ease with window.scroll or another input represented by a normalized value/ progress (a number between 0 and 1)i see mathf-ease.html in the /examples folder where there is element and progress level easing to smooth interaction.

      Also related is [[Interpolate]].

      Parameters

      • start: number

        The start of the range to lerp.

      • end: number

        The target of the range to lerp.

      • progress: number

        A value between 0-1 representing the progress of the lerp.

      • easeFunction: Function = EASE.linear

        An easing function. See [[ease]]

      Returns number