Question

Je le morceau de code suivant

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

Ce nombre met hors d'une manière linéaire de ce type de {0, 0,1, 0,2, ..., 0,9, 1,0} je voudrais appliquer le cube (ou arrière) facilitant l'équation de sorte que les numéros de sortie augmentent ou diminuent graduellement


UPDATE

Je ne sais pas si ma mise en œuvre si elle est correcte mais je reçois courbe comme prévu

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 );
}
Était-ce utile?

La solution

Easin cubique Fonction

/**
 * @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 cubique Fonction

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

Vous trouverez ici othere équations utiles: http://www.gizma.com/easing/# CUB1

Mettre ce code dans un certain temps, que vous avez don avant et vous aurez votre sortie cube nombre décroissant.

Autres conseils

Vous pouvez utiliser le code de plugin 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;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top