作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 TChromeTabs 中实现选项卡的流畅移动。我可以看到缓动公式 here ,但我不是数学家,也不知道如何将其转化为代码。到目前为止,我的尝试毫无进展。
是否有可用的 Easing 函数的 Delphi 实现?
最佳答案
我在网上找到了几个有用的例子,并使用这些算法编写了我自己的 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;
...
关于delphi - Delphi中EaseIn、EaseOut函数的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13952801/
我目前正在尝试使用 SwiftUI 创建动画以在多种颜色之间转换,但是,我遇到了一个特定问题。该代码有效,但是,它只能更改 2-3 种不同的颜色,然后重置回原始颜色。我还通过 GitHub 使用名为“
我想为文本信息和 SF 符号设置一个 easeIn/moveUp 动画 onAppear。此后,我只希望 SF 符号永远按比例放大和缩小。目前,我已经设法永远按比例缩小,但是当我设法链接时,easeI
我有一个代码: NSArray * imageArray = [[NSArray alloc] initWithObjects: [UIIma
我是一名优秀的程序员,十分优秀!