Function Repository Resource:

EasingFunction

Source Notebook

Get a named easing function, representing rate of change of a parameter over time

Contributed by: Daniel Sanchez

ResourceFunction["EasingFunction"]["name"]

returns a pure function representing the easing function given by "name".

ResourceFunction["EasingFunction"]["name", "prop"]

returns the property "prop" for a given easing function.

ResourceFunction["EasingFunction"][All]

returns a Dataset of all available easing functions.

Details

Easing functions specify the rate of change of a parameter over time.
All easing functions and their implementations were obtained from the Easing Functions Cheat Sheet.
Functions returned have the form Function[t,], where t represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
Supported easing functions include:
"InSine"
"OutSine"
"InOutSine"
"InQuad"
"OutQuad"
"InOutQuad"
"InCubic"
"OutCubic"
"InOutCubic"
"InQuart"
"OutQuart"
"InOutQuart"
"InQuint"
"OutQuint"
"InOutQuint"
"InExpo"
"OutExpo"
"InOutExpo"
"InCirc"
"OutCirc"
"InOutCirc"
"InBack"
"OutBack"
"InOutBack"
"InElastic"
"OutElastic"
"InOutElastic"
"InBounce"
"OutBounce"
"InOutBounce"
Available properties include:
"ColorFunction"a Function that can be used as the value of ColorFunction
"Compile"a CompiledFunction
"Function"a Function representing the easing function
"Icon"an icon
"Plot"a Plot in the range 0 to 1
"PureFunction"a pure function
ResourceFunction["EasingFunction"][All,"prop"] returns the value of "prop" for all supported easing functions.
ResourceFunction["EasingFunction"][] is equivalent to ResourceFunction["EasingFunction"][All].
ResourceFunction["EasingFunction"]["Names"] returns a list with the names of all supported easing functions.
ResourceFunction["EasingFunction"]["Properties"] returns a list of all the available properties.

Examples

Basic Examples (3) 

Get an easing function:

In[1]:=
ease = ResourceFunction["EasingFunction"]["InElastic"]
Out[1]=

Make a plot in the range 0 to 1 using that function:

In[2]:=
Plot[ease[t], {t, 0, 1}, PlotRange -> All]
Out[2]=

Obtain a list of all the available properties:

In[3]:=
ResourceFunction["EasingFunction"]["Properties"]
Out[3]=

Obtain an icon for a given easing function:

In[4]:=
ResourceFunction["EasingFunction"]["InOutBack", "Icon"]
Out[4]=

Scope (2) 

Get a Dataset with all the available easing functions:

In[5]:=
ResourceFunction["EasingFunction"][All]
Out[5]=

Get a plot of all easing functions:

In[6]:=
ResourceFunction["EasingFunction"][All, "Plot"]
Out[6]=

Properties and Relations (7) 

Get a pure function that can be passed along to ColorFunction:

In[7]:=
Plot[
 ResourceFunction["EasingFunction"]["InOutBack"][t], {t, 0, 1},
 ColorFunction -> ResourceFunction["EasingFunction"]["InOutBack", "ColorFunction"]
 ]
Out[7]=

Compile a given easing function:

In[8]:=
cf = ResourceFunction["EasingFunction"]["InOutSine", "Compile"]
Out[8]=

Compute the timing of the uncompiled function:

In[9]:=
With[{func = ResourceFunction["EasingFunction"]["InOutSine"]},
 func[0.5] // RepeatedTiming
 ]
Out[9]=

Compare against the compiled version:

In[10]:=
cf[0.5] // RepeatedTiming
Out[10]=

The compiled function threads over lists:

In[11]:=
cf[Subdivide[7]]
Out[11]=

Additional Compile options can be specified:

In[12]:=
ResourceFunction["EasingFunction"]["InOutSine", "Compile", CompilationTarget -> "C"]
Out[12]=

Obtain a Function representing the easing function:

In[13]:=
ResourceFunction["EasingFunction"]["OutCirc", "Function"]
Out[13]=

EasingFunction["name"] gives the same result:

In[14]:=
ResourceFunction["EasingFunction"]["OutCirc"] === ResourceFunction["EasingFunction"]["OutCirc", "Function"]
Out[14]=

Get an icon of the easing function:

In[15]:=
ResourceFunction["EasingFunction"]["InOutBounce", "Icon"]
Out[15]=

Plot a given easing function:

In[16]:=
ResourceFunction["EasingFunction"]["InOutElastic", "Plot"]
Out[16]=

Additional Plot options can be specified:

In[17]:=
ResourceFunction["EasingFunction"]["InOutElastic", "Plot", Background -> Black, AxesStyle -> Directive[AbsoluteThickness[3.], Opacity[.5], White]]
Out[17]=

Get a pure function version of the easing function:

In[18]:=
ResourceFunction["EasingFunction"]["InOutSine", "PureFunction"]
Out[18]=

Neat Examples (2) 

Compare the effect of various easing functions on moving text:

In[19]:=
Manipulate[
 Graphics[Text[
   "Zoom!", {ResourceFunction["EasingFunction"][name][x], 0}], PlotRange -> {{-0.1, 1.1}, {-0.1, 0.1}}], {{name, "InBounce", "easing function"}, ResourceFunction["EasingFunction"]["Names"]}, {x, 0, 1, ControlType -> Animator, AnimationRunning -> False}, SaveDefinitions -> True]
Out[19]=

Compare the effect of various easing functions in shading a picture:

In[20]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/7880b776-784b-496e-9bd3-244598a33143"]
Out[20]=

Publisher

Daniel Sanchez

Version History

  • 1.0.1 – 03 August 2021

Related Resources

License Information