2011-04-29 110 views
4

我可以計算出所有多項式函數的公式,例如 。對於QuinticEase公式爲:緩動函數的數學公式(ElasticEase,CircleEase,BounceEase,BackEase,PowerEase)?

(X - 1)^ 5 + 1

但什麼是用於ElasticEase,CircleEase,BounceEase,BackEase,或PowerEase數學公式?

他們都應該在範圍0..1

+0

它只是X^5實際。 – 2011-04-29 22:58:01

+0

要在代碼中使用寬鬆函數,它們將被移至t = 0到t = 1的範圍。 (x-1)^ 5進行x軸移位,+1進行y軸移位。 – j00hi 2011-04-29 23:01:09

+0

EasingFunction使用的輸入始終是標準化的,因此介於0和1之間。 – 2011-04-29 23:05:13

回答

4

大多數公式可以發現on MSDN,如果它不是在那裏檢查各自輕鬆的子網站。

對於其中引用沒有命名該函數的更復雜函數,可以使用反編譯器ILSpy來查看各個類上的EaseInCore方法的代碼。

+1

只有圖像。在0..1範圍內找不到緩動函數的任何公式。 – j00hi 2011-04-29 22:59:05

+0

不正確,在[CircleEase](http://msdn.microsoft.com/zh-cn/library/system.windows.media.animation.circleease.aspx)網站上的公式爲f(t)= 1 - Sqrt (1-t^2)「。 – 2011-04-29 23:00:58

+0

哦,沒有看到。謝謝!不幸的是,我對ElasticEase和BounceEase的公式特別感興趣。只是那些公式不存在。 – j00hi 2011-04-29 23:05:14

6

看到這個JavaScript項目http://jstween.blogspot.com,在底部你會發現Tween.js文件裏面有需要的公式。

+0

酷!謝謝!如果我能接受第二個答案,那將是你的。 – j00hi 2011-04-30 07:21:03

1

我發現含有不同的語言實現不錯的網站:Robert Penner's Easing Functions

例如,彈性寬鬆的C++代碼:

float Elastic::easeIn (float t,float b , float c, float d) { 
    if (t==0) return b; if ((t/=d)==1) return b+c; 
    float p=d*.3f; 
    float a=c; 
    float s=p/4; 
    float postFix =a*pow(2,10*(t-=1)); // this is a fix, again, with post-increment operators 
    return -(postFix * sin((t*d-s)*(2*PI)/p)) + b; 
} 

float Elastic::easeOut(float t,float b , float c, float d) { 
    if (t==0) return b; if ((t/=d)==1) return b+c; 
    float p=d*.3f; 
    float a=c; 
    float s=p/4; 
    return (a*pow(2,-10*t) * sin((t*d-s)*(2*PI)/p) + c + b); 
} 

float Elastic::easeInOut(float t,float b , float c, float d) { 
    if (t==0) return b; if ((t/=d/2)==2) return b+c; 
    float p=d*(.3f*1.5f); 
    float a=c; 
    float s=p/4; 

    if (t < 1) { 
     float postFix =a*pow(2,10*(t-=1)); // postIncrement is evil 
     return -.5f*(postFix* sin((t*d-s)*(2*PI)/p)) + b; 
    } 
    float postFix = a*pow(2,-10*(t-=1)); // postIncrement is evil 
    return postFix * sin((t*d-s)*(2*PI)/p)*.5f + c + b; 
}