Skip to content

9.2 Math easing functions

Davide Magni edited this page Jun 1, 2017 · 1 revision

Easing functions specify the rate of change of a parameter over time. The parameter can be anything: a knob, the movement of a label over the UI, anything that goes from a start point to an end point. In real life, almost nothing has a linear movement. When it comes to musical instruments, any real movement of the player can be approximated to a certain curve.

Thanks to Kontakt 5.6's new math features, we managed to add a bunch of very useful easing functions. All these functions are inline functions, so you may use them in if statements, loops and any other inline application. You can also combine multiple easing functions together in order to obtain new curves.

All these functions return real values! If you want to convert their values to integer values - e.g. to use an easing function to set the movement of a knob - you may use the following syntax:

function move_knob 
	declare ~time := 0.0
	// 
	while ~time <= 1000.0
		knob := real_to_int(round(math.easeIn_sine(~time, 0.0, 500000.0, 1000.0)))
		~time := ~time  + 1.0	// increment 
		wait(1000)	// Each loop's round lasts 1 millisecond
	end while
end function

This function moves a knob following the ease-in Sine curve. The automation goes from the value 0 of the knob to 500000. The automation lasts one second. The resolution of the movement is 1 millisecond, meaning that the new value of the knob will be set every 1 millisecond.

Note that in order to convert the output of the easing function into an integer, we are using not only real_to_int(), but round() as well. This ensures maximum precision, as real_to_int() simply truncates the decimal part of the real number.

Please refer to the Easing Functions Cheat Sheet in order to see how the available shapes are.

Many thanks to Paolo Ingraito from FluffyAudio for the precious help!

math.linear_tween

math.linear_tween(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeIn_quad

math.easeIn_quad(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_quad

math.easeOut_quad(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeInOut_quad

math.easeInOut_quad(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeIn_cubic

math.easeIn_cubic(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_cubic

math.easeOut_cubic(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeInOut_cubic

math.easeInOut_cubic(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeIn_quartic

math.easeIn_quartic(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_quartic

math.easeOut_quartic(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeInOut_quartic

math.easeInOut_quartic(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeIn_sine

math.easeIn_sine(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_sine

math.easeOut_sine(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeInOut_sine

math.easeInOut_sine(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeIn_expo

math.easeIn_expo(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_expo

math.easeOut_expo(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeInOut_expo

math.easeInOut_expo(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeIn_circ

math.easeIn_circ(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_circ

math.easeOut_circ(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeInOut_circ

math.easeInOut_circ(<time>, <v_start>, <v_end>, <duration>)

  • time Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start Value to start the easing process from. This must be a real value.
  • v_end Value where the easing process ends. This must be a real value.
  • duration Total duration of the easing process. This must be a real value.

math.easeOut_elastic

math.easeOut_elastic(<time>, <v_start>, <v_end>, <duration>, <elastic>)

  • time, <v_start> Current time for the easing process. This must be a real number indicating seconds, milliseconds, frames, anything you need for your current application.
  • v_start, <v_end> Value to start the easing process from. This must be a real value.
  • time, <duration> Value where the easing process ends. This must be a real value. ** time <elastic> Total duration of the easing process. This must be a real value.
Clone this wiki locally