指數緩動給人的感覺是加速度很大.
它的原始公式來自:P(t) = Math.Pow(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;
//加速
//return delta * Math.Pow(2, 10 * (value - 1)) + from;
//減速
//return delta * (-Math.Pow(2, -10 * value) + 1) + from;
//先加速,後減速
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;
}
本文配套源碼