[英]Help formulating a cubic easing equation
我有以下代碼
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}我想應用立方(in或out)緩動方程,使輸出數逐漸增加或減少
UPDATE
不確定我的實現是否正確,但我得到了預期的曲線
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 );
}
/**
* @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;
}
/**
* @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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.