原文:
WPF与缓动(四) 弧形缓动WPF与缓动(四) 弧形缓动
周银辉
弧形缓动就是其缓动曲线为一段圆弧, 如何我们假设圆弧上的点的斜率为速度的话,那么可以想像其速度的变化多么具有戏剧性, 其加速或减速来得很突然, 与5次缓动差不多.
参考以下代码:
//圆形缓动
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;
double t = value * this.Duration.TimeSpan.Ticks;
double d = this.Duration.TimeSpan.Ticks;
//加速
//return delta * (1-Math.Sqrt(1-(t/=d)*t)) + from;
//减速
//return delta * Math.Sqrt(1 - (t = t / d - 1) * t) + from;
//先加速,后减速
if ((t /= (d / 2)) < 1)
return delta / 2 * (1 - Math.Sqrt(1 - t * t)) + from;
}
return delta / 2 * (Math.Sqrt(1 - (t -= 2) * t) + 1) + from;
}
下载Demo