指數緩動基於 $P(t) = 2^{10(t-1)}$,特徵是初期極緩慢、後期極度爆發(或反向),給人「極大加速度」的強烈感受。適合模擬火箭發射、彈簧釋放等極端動態。
// 指數緩動
protected override double GetCurrentValueCore(
double defaultOriginValue,
double defaultDestinationValue,
AnimationClock animationClock)
{
double from = (this.From == null ? defaultDestinationValue : (double)this.From);
double to = (this.To == null ? defaultOriginValue : (double)this.To);
double delta = to - from;
double value = animationClock.CurrentProgress.Value;
// 加速 (Ease In)
// return delta * Math.Pow(2, 10 * (value - 1)) + from;
// 減速 (Ease Out)
// return delta * (-Math.Pow(2, -10 * value) + 1) + from;
// 先加速後減速 (Ease InOut)
double t = value * this.Duration.TimeSpan.Ticks;
double d = this.Duration.TimeSpan.Ticks;
if ((t /= (d / 2)) < 1)
{
return delta / 2 * Math.Pow(2, 10 * (t - 1)) + from;
}
return delta / 2 * (-Math.Pow(2, -10 * --t) + 2) + from;
}
DoubleAnimationBase 並定義依賴屬性。Power 暴露給 XAML 調整劇烈程度。指數緩動以極端的非線性曲線創造強烈視覺張力,是動畫設計師工具箱中的「重口味」利器。配合前文的 N 次方、正弦、圓弧緩動,已構建完整的自訂緩動函數庫。