帮助形成一个三次缓和方程



我有以下一段代码

int steps = 10;
for (int i = 0; i <= steps; i++) {
    float t = i / float(steps);
    console.log( "t  " + t );
}

输出像这样的线性方式的数字{0,0.1,0.2,…, 0.9, 1.0}我想应用三次(入或出)缓和方程,以便输出数逐渐增加或减少


不确定我的实现是否正确,但我得到了预期的曲线

float b = 0;
float c = 1;
float d = 1;
for (int i = 0; i <= steps; i++) {
    float t = i / float(steps);
    t /= d;
    float e = c * t * t * t + b;
    console.log( "e  " + e );
    //console.log( "t  " + t );
}

EasIn Cubic Function

/**
 * @param {Number} t The current time
 * @param {Number} b The start value
 * @param {Number} c The change in value
 * @param {Number} d The duration time
 */ 
function easeInCubic(t, b, c, d) {
   t /= d;
   return c*t*t*t + b;
}

EaseOut三次函数

/**
 * @see {easeInCubic}
 */
function easeOutCubic(t, b, c, d) {
   t /= d;
   t--;
   return c*(t*t*t + 1) + b;
}

在这里你可以找到其他有用的公式:http://www.gizma.com/easing/#cub1

将这段代码放入一会儿,就像您之前所做的那样,您将得到您的输出立方递减数

你可以使用jQuery Easing插件中的代码:http://gsgd.co.uk/sandbox/jquery/easing/

/*
*  t: current time
*  b: begInnIng value
*  c: change In value
*  d: duration
*/
easeInCubic: function (x, t, b, c, d) {
    return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t*t + b;
    return c/2*((t-=2)*t*t + 2) + b;
}

最新更新