public EasingView() { InitializeComponent(); Loaded += delegate { Polyline polyline = new Polyline(); for (int px = 0; px <= rect.Width; px++) { double x = (double)px / rect.Width; double y = EasingFunction.Ease(x); polyline.Points.Add(new Point(px, rect.Height - y * rect.Height)); } polyline.Stroke = new SolidColorBrush(Colors.Blue); polyline.Fill = null; Canvas.SetTop(polyline, 5); Canvas.SetLeft(polyline, 5); LayoutRoot.Children.Add(polyline); }; }
protected override void UpdateTarget(float normalizedTime) { Vector2 position = Target.Position; position.Y = EasingFunction.Ease(normalizedTime, From, To); Target.Position = position; }
protected override void UpdateTarget(float normalizedTime) { float x = EasingFunction.Ease(normalizedTime, From.X, To.X); float y = EasingFunction.Ease(normalizedTime, From.Y, To.Y); Target.Position = new Vector2(x, y); }
public void EaseInOutTest() { EasingFunction.Mode = EasingMode.EaseInOut; TestEase(); // Check center. Assert.IsTrue(Numeric.AreEqual(0.5f, EasingFunction.Ease(0.5f)), "Easing function using EaseInOut failed for t = 0.5."); }
protected override void UpdateTarget(float normalizedTime) { float from = From ? 1f : 0f; float to = To ? 1f : 0f; float value = EasingFunction.Ease(normalizedTime, from, to); Target.FlipX = value > 0.5f; }
void CompositionTarget_Rendering(object sender, EventArgs e) { if (IsAnimationFinished) { return; } var elapsedTime = DateTime.Now.Subtract(StartTime); if (elapsedTime < TimeSpan.Zero) { return; } var magnitude = Math.Abs(Value - PreviousValue); var totalTicks = (long)(((Double)Duration.Ticks) * (magnitude / Math.Max(1, StepSize))); totalTicks = Math.Min(totalTicks, MaxDuration.Ticks); var totalDuration = new TimeSpan(totalTicks); if (elapsedTime < totalDuration) { if (FinalStoryboard != null) { FinalStoryboard.Stop(); } var normalizedTime = (Double)elapsedTime.Ticks / (Double)totalDuration.Ticks; var easing = (EasingFunction == null ? normalizedTime // if there is no easing function, use linear animation. : EasingFunction.Ease(normalizedTime)); //Ease(normalizedTime); var currentDisplacement = ((Value - PreviousValue) * easing); SetText(PreviousValue + currentDisplacement); } else { SetText(Value); if (FinalStoryboard != null) { FinalStoryboard.Begin(); } IsAnimationFinished = true; } }
internal override void Update() { double deltaV = To - From; double easing = 1; if (EasingFunction != null) // <- that's important. { easing = EasingFunction.Ease(Percentage); } CurrentValue = From + (Percentage * deltaV * easing); base.Update(); // <- this too. }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) { var from = From; if (from == GridLength.Auto) { from = (GridLength)defaultOriginValue; } var to = To; if (to == GridLength.Auto) { to = (GridLength)defaultDestinationValue; } if (from.GridUnitType != to.GridUnitType) { // cannot animate return(to); } if (from.IsAuto) { // cannot animate return(to); } double ratio = animationClock.CurrentProgress.Value; if (EasingFunction != null) { ratio = EasingFunction.Ease(ratio); } var diff = to.Value - from.Value; var result = from.Value + diff * ratio; return(new GridLength(result, from.GridUnitType)); }
public void EaseInOutTest() { EasingFunction.Mode = EasingMode.EaseInOut; TestEase(); // Check center. Assert.IsTrue(Numeric.AreEqual(0.5f, EasingFunction.Ease(0.5f)), "Easing function using EaseInOut failed for t = 0.5."); EasingFunction.Oscillations = 4; EasingFunction.Springiness = 4; TestEase(); Assert.IsTrue(Numeric.AreEqual(0.5f, EasingFunction.Ease(0.5f)), "Easing function using EaseInOut failed for t = 0.5."); EasingFunction.Oscillations = 0; EasingFunction.Springiness = 0; TestEase(); Assert.IsTrue(Numeric.AreEqual(0.5f, EasingFunction.Ease(0.5f)), "Easing function using EaseInOut failed for t = 0.5."); EasingFunction.Oscillations = -1; EasingFunction.Springiness = -1; TestEase(); Assert.IsTrue(Numeric.AreEqual(0.5f, EasingFunction.Ease(0.5f)), "Easing function using EaseInOut failed for t = 0.5."); }
protected override GridLength GetCurrentValueCore(GridLength defaultOriginValue, GridLength defaultDestinationValue, AnimationClock animationClock) { if (From == null && To == null && By == null) { throw new Exception("Unknown animation type"); } GridLength from = From ?? defaultOriginValue; GridLength to = To ?? defaultDestinationValue; double?progress = animationClock.CurrentProgress; // What if it is null? Is GetCurrentValueCore ever called? //https://msdn.microsoft.com/en-us/library/system.windows.media.animation.clock.currentprogress(v=vs.110).aspx if (EasingFunction != null) { progress = EasingFunction.Ease((double)progress); } if (To == null && By != null) { if (From == null) { To = new GridLength(defaultOriginValue.Value + (double)By); } else { To = new GridLength(From.Value.Value + (double)By); } } if (from.GridUnitType != to.GridUnitType) { return(to); } return(new GridLength(from.Value + (to.Value - from.Value) * progress.Value, from.GridUnitType)); }
void CompositionTarget_Rendering(object sender, EventArgs e) { var elapsedTime = DateTime.Now.Subtract(StartTime); if (elapsedTime < TimeSpan.Zero) { return; } var totalTicks = (long)Duration.Ticks; var totalDuration = new TimeSpan(totalTicks); if (elapsedTime < totalDuration) { var normalizedTime = (Double)elapsedTime.Ticks / (Double)totalDuration.Ticks; var easing = (EasingFunction == null ? normalizedTime // if there is no easing function, use linear animation. : EasingFunction.Ease(normalizedTime)); //Ease(normalizedTime); var deltaTime = normalizedTime - PreviousTimeValue; //If the delta easing indicates that threshold is exceeded. if (Math.Abs(deltaTime) > (Double)Duration.TotalSeconds / (ChangesPerSecond)) { AssociatedObject.Text = GetNewRandomText(easing); PreviousTimeValue = normalizedTime; } } else { AssociatedObject.Text = Value; } }
protected override void UpdateTarget(float normalizedTime) { Target.Scale = EasingFunction.Ease(normalizedTime, From, To); }
protected override void UpdateTarget(float normalizedTime) { Target.ZIndex = (int)EasingFunction.Ease(normalizedTime, From, To); }