質問

次のコードがあります

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機能

/**
 * @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;
}

easeaseout cubic関数

/**
 * @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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top