smoothstep

image This function makes a smooth transition from 0 to 1 beginning at threshold a and ending at threshold b. In order to do this, smoothstep contains a cubic function whose slope is 0 at a and b and whose value is 0 at a and 1 at b. There is only one cubic function that has these properties for a = 0 and b = 1, namely the function 3x² - 2x³. This function can be used to provide smooth transitions between values or to "ease" animation in and out.

Downloadsmoothstep(a,b,t)   Returns a smooth transition from 0 to 1 when t is between a and b.
/*
**  Usage:
**      smoothstep(a,b,t)
**
**  Arguments:
**      a       upper bound, real
**      b       lower bound, real
**      t       value, real
**
**  Returns:
**      0 when (t < a), 1 when (t >= b),
**      a smooth transition from 0 to 1 otherwise,
**      or (-1) on error (a == b)
**
**  GMLscripts.com
*/

{
    var p;
    if (argument2 < argument0) return 0;
    if (argument2 >= argument1) return 1;
    if (argument0 == argument1) return -1;
    p = (argument2 - argument0) / (argument1 - argument0);
    return (p * p * (3 - 2 * p));
}

Click if you've used this script[Please Login]
Projects: 2

 Contributor: xot


comments powered by Disqus