2012-12-19 92 views
6

我試圖在TChromeTabs中實現製表符的流體移動。我可以看到緩解公式here,但我不是數學家,也不知道如何將其轉換爲代碼。迄今爲止我的嘗試讓我無處可尋。在Delphi中實現EaseIn,EaseOut功能

Easing功能的Delphi實現是否可用?

+2

您可以在這裏測試緩動效應類型http://gizma.com/easing/ aditionaly它有一些解釋和一些代碼示例。 –

+0

你有任何代碼嗎?例如需要填寫特定緩動功能的存根? –

回答

5

我在網上找到了幾個有用的例子,並使用這些算法來編寫我自己的Delphi Easing函數。它們是:

... 

type 
    TChromeTabsEaseType = (
    ttlinearTween, 
    tteaseInQuad, 
    tteaseOutQuad, 
    tteaseInOutQuad, 
    tteaseInCubic, 
    tteaseOutCubic, 
    tteaseInOutCubic, 
    tteaseInQuart, 
    tteaseOutQuart, 
    tteaseInOutQuart, 
    tteaseInQuint, 
    tteaseOutQuint, 
    tteaseInOutQuint, 
    tteaseInSine, 
    tteaseOutSine, 
    tteaseInOutSine, 
    tteaseInExpo, 
    tteaseOutExpo, 
    tteaseInOutExpo, 
    tteaseInCirc, 
    tteaseOutCirc, 
    tteaseInOutCirc 
); 

    function CalculateEase(CurrentTime, StartValue, ChangeInValue, Duration: Real; EaseType: TChromeTabsEaseType): Real; overload; 
    function CalculateEase(StartPos, EndPos, PositionPct: Real; EaseType: TChromeTabsEaseType): Real; overload; 

implementation 

    function CalculateEase(CurrentTime, StartValue, ChangeInValue, Duration: Real; EaseType: TChromeTabsEaseType): Real; 
    begin 
     case EaseType of 
     ttLinearTween: 
      begin 
      Result := ChangeInValue * CurrentTime/Duration + StartValue; 
      end; 

     ttEaseInQuad: 
      begin 
      CurrentTime := CurrentTime/Duration; 

       Result := ChangeInValue * CurrentTime * CurrentTime + StartValue; 
      end; 

     ttEaseOutQuad: 
      begin 
      CurrentTime := CurrentTime/Duration; 

       Result := -ChangeInValue * CurrentTime * (CurrentTime-2) + StartValue; 
      end; 

     ttEaseInOutQuad: 
      begin 
      CurrentTime := CurrentTime/(Duration/2); 

      if CurrentTime < 1 then 
       Result := ChangeInValue/2 * CurrentTime * CurrentTime + StartValue 
      else 
      begin 
       CurrentTime := CurrentTime - 1; 
       Result := -ChangeInValue/2 * (CurrentTime * (CurrentTime - 2) - 1) + StartValue; 
      end; 
      end; 

     ttEaseInCubic: 
      begin 
      CurrentTime := CurrentTime/Duration; 

      Result := ChangeInValue * CurrentTime * CurrentTime * CurrentTime + StartValue; 
      end; 

     ttEaseOutCubic: 
      begin 
      CurrentTime := (CurrentTime/Duration) - 1; 

      Result := ChangeInValue * (CurrentTime * CurrentTime * CurrentTime + 1) + StartValue; 
      end; 

     ttEaseInOutCubic: 
      begin 
      CurrentTime := CurrentTime/(Duration/2); 

      if CurrentTime < 1 then 
       Result := ChangeInValue/2 * CurrentTime * CurrentTime * CurrentTime + StartValue 
      else 
      begin 
       CurrentTime := CurrentTime - 2; 

       Result := ChangeInValue/2 * (CurrentTime * CurrentTime * CurrentTime + 2) + StartValue; 
      end; 
      end; 

     ttEaseInQuart: 
      begin 
      CurrentTime := CurrentTime/Duration; 

      Result := ChangeInValue * CurrentTime * CurrentTime * CurrentTime * CurrentTime + StartValue; 
      end; 

     ttEaseOutQuart: 
      begin 
      CurrentTime := (CurrentTime/Duration) - 1; 

      Result := -ChangeInValue * (CurrentTime * CurrentTime * CurrentTime * CurrentTime - 1) + StartValue; 
      end; 

     ttEaseInOutQuart: 
      begin 
       CurrentTime := CurrentTime/(Duration/2); 

      if CurrentTime < 1 then 
       Result := ChangeInValue/2 * CurrentTime * CurrentTime * CurrentTime * CurrentTime + StartValue 
      else 
      begin 
       CurrentTime := CurrentTime - 2; 

       Result := -ChangeInValue/2 * (CurrentTime * CurrentTime * CurrentTime * CurrentTime - 2) + StartValue; 
      end; 
      end; 

     ttEaseInQuint: 
      begin 
      CurrentTime := CurrentTime/Duration; 

      Result := ChangeInValue * CurrentTime * CurrentTime * CurrentTime * CurrentTime * CurrentTime + StartValue; 
      end; 

     ttEaseOutQuint: 
      begin 
      CurrentTime := (CurrentTime/Duration) - 1; 

       Result := ChangeInValue * (CurrentTime * CurrentTime * CurrentTime * CurrentTime * CurrentTime + 1) + StartValue; 
      end; 

     ttEaseInOutQuint: 
      begin 
      CurrentTime := CurrentTime/(Duration/2); 
      if CurrentTime < 1 then 
       Result := ChangeInValue/2 * CurrentTime * CurrentTime * CurrentTime * CurrentTime * CurrentTime + StartValue 
      else 
      begin 
       CurrentTime := CurrentTime - 2; 

       Result := ChangeInValue/2 * (CurrentTime * CurrentTime * CurrentTime * CurrentTime * CurrentTime + 2) + StartValue; 
      end; 
      end; 

     ttEaseInSine: 
      begin 
       Result := -ChangeInValue * Cos(CurrentTime/Duration * (PI/2)) + ChangeInValue + StartValue; 
      end; 

     ttEaseOutSine: 
      begin 
       Result := ChangeInValue * Sin(CurrentTime/Duration * (PI/2)) + StartValue; 
      end; 

     ttEaseInOutSine: 
      begin 
      Result := -ChangeInValue/2 * (Cos(PI * CurrentTime/Duration) - 1) + StartValue; 
      end; 

     ttEaseInExpo: 
      begin 
      Result := ChangeInValue * Power(2, 10 * (CurrentTime/Duration - 1)) + StartValue; 
      end; 

     ttEaseOutExpo: 
      begin 
      Result := ChangeInValue * (-Power(2, -10 * CurrentTime/Duration) + 1) + StartValue; 
      end; 

     ttEaseInOutExpo: 
      begin 
      CurrentTime := CurrentTime/(Duration/2); 

      if CurrentTime < 1 then 
       Result := ChangeInValue/2 * Power(2, 10 * (CurrentTime - 1)) + StartValue 
      else 
      begin 
       CurrentTime := CurrentTime - 1; 

       Result := ChangeInValue/2 * (-Power(2, -10 * CurrentTime) + 2) + StartValue; 
      end; 
      end; 

     ttEaseInCirc: 
      begin 
      CurrentTime := CurrentTime/Duration; 

       Result := -ChangeInValue * (Sqrt(1 - CurrentTime * CurrentTime) - 1) + StartValue; 
      end; 

     ttEaseOutCirc: 
      begin 
      CurrentTime := (CurrentTime/Duration) - 1; 

      Result := ChangeInValue * Sqrt(1 - CurrentTime * CurrentTime) + StartValue; 
      end; 

     ttEaseInOutCirc: 
      begin 
      CurrentTime := CurrentTime/(Duration/2); 

      if CurrentTime < 1 then 
       Result := -ChangeInValue/2 * (Sqrt(1 - CurrentTime * CurrentTime) - 1) + StartValue 
      else 
      begin 
       CurrentTime := CurrentTime - 2; 

       Result := ChangeInValue/2 * (Sqrt(1 - CurrentTime * CurrentTime) + 1) + StartValue; 
      end; 
      end; 
     end; 
    end; 

    function CalculateEase(StartPos, EndPos, PositionPct: Real; EaseType: TChromeTabsEaseType): Real; 
    var 
     t, b, c, d: Real; 
    begin 
     c := EndPos - StartPos; 
     d := 100; 
     t := PositionPct; 
     b := StartPos; 

     Result := CalculateEase(t, b, c, d, EaseType); 
    end; 

    ... 
+0

不錯;)你應該接受你在這種情況下的答案:) –

+0

@Diego - 我會,但我需要等待2天才會讓我:0) – norgepaul

+0

那代碼的許可證呢?在商業應用中使用它可以嗎? – Flash