Garry's Mod Wiki

math.ease

An easing library that allows you to interpolate with various kinds of smoothing functions. To use with Lerp, input what you would to the fraction argument in one of these easing functions and then the output of that into the Lerp fraction argument.

Example

Example usage with Lerp and math.ease.InSine

-- Define a wrapper function to make it easier to work with local function easedLerp(fraction, from, to) return Lerp(math.ease.InSine(fraction), from, to) end -- Compare with the non-eased version of Lerp print(easedLerp(0.25, 0, 1)) print(Lerp(0.25, 0, 1)) print(easedLerp(0.25, 0, 5)) print(Lerp(0.25, 0, 5))
Output:
0.076120467488713 0.25 0.38060233744357 1.25

A brief visual example of different easing methods

easing_examples.gif

Methods

number math.ease.InBack( number fraction )
Eases in by reversing the direction of the ease slightly before returning. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.InBounce( number fraction )
Eases in like a bouncy ball. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.InCirc( number fraction )
Eases in using a circular function.
number math.ease.InCubic( number fraction )
Eases in by cubing the fraction.
number math.ease.InElastic( number fraction )
Eases in like a rubber band. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.InExpo( number fraction )
Eases in using an exponential equation with a base of 2 and where the fraction is used in the exponent.
number math.ease.InOutBack( number fraction )
Eases in and out by reversing the direction of the ease slightly before returning on both ends. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.InOutBounce( number fraction )
Eases in and out like a bouncy ball. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.InOutCirc( number fraction )
Eases in and out using a circular function.
number math.ease.InOutCubic( number fraction )
Eases in and out by cubing the fraction.
number math.ease.InOutElastic( number fraction )
Eases in and out like a rubber band. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.InOutExpo( number fraction )
Eases in and out using an exponential equation with a base of 2 and where the fraction is used in the exponent.
number math.ease.InOutQuad( number fraction )
Eases in and out by squaring the fraction.
number math.ease.InOutQuart( number fraction )
Eases in and out by raising the fraction to the power of 4.
number math.ease.InOutQuint( number fraction )
Eases in and out by raising the fraction to the power of 5.
number math.ease.InOutSine( number fraction )
Eases in and out using math. sin.
number math.ease.InQuad( number fraction )
Eases in by squaring the fraction.
number math.ease.InQuart( number fraction )
Eases in by raising the fraction to the power of 4.
number math.ease.InQuint( number fraction )
Eases in by raising the fraction to the power of 5.
number math.ease.InSine( number fraction )
Eases in using math. sin.
number math.ease.OutBack( number fraction )
Eases out by reversing the direction of the ease slightly before finishing. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.OutBounce( number fraction )
Eases out like a bouncy ball. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.OutCirc( number fraction )
Eases out using a circular function.
number math.ease.OutCubic( number fraction )
Eases out by cubing the fraction.
number math.ease.OutElastic( number fraction )
Eases out like a rubber band. This doesn't work properly when used with Lerp as it clamps the fraction between 0 and 1. Using your own version of Lerp that is unclamped would be necessary instead.
number math.ease.OutExpo( number fraction )
Eases out using an exponential equation with a base of 2 and where the fraction is used in the exponent.
number math.ease.OutQuad( number fraction )
Eases out by squaring the fraction.
number math.ease.OutQuart( number fraction )
Eases out by raising the fraction to the power of 4.
number math.ease.OutQuint( number fraction )
Eases out by raising the fraction to the power of 5.
number math.ease.OutSine( number fraction )
Eases out using math. sin.