public static EasingFunctionBase GetEasingFunction() { EasingFunctionBase result = null; switch (random.Next(5)) { case 0: result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 }; break; case 1: result = new BounceEase() { EasingMode = EasingMode.EaseOut, Bounces = 3, Bounciness = 8 }; break; case 2: result = new CircleEase() { EasingMode = EasingMode.EaseInOut }; break; case 3: result = new CubicEase() { EasingMode = EasingMode.EaseIn }; break; case 4: result = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 4 }; break; case 5: result = new SineEase() { EasingMode = EasingMode.EaseInOut }; break; default: result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 }; break; } return result; }
private void AnimateEntry(Size targetSize) { var svi = GuiHelpers.GetParentObject<ScatterViewItem>(this, false); if (svi != null) { // Easing function provide a more natural animation IEasingFunction ease = new BackEase {EasingMode = EasingMode.EaseOut, Amplitude = 0.3}; var duration = new Duration(TimeSpan.FromMilliseconds(500)); var w = new DoubleAnimation(0.0, targetSize.Width, duration) {EasingFunction = ease}; var h = new DoubleAnimation(0.0, targetSize.Height, duration) {EasingFunction = ease}; var o = new DoubleAnimation(0.0, 1.0, duration); // Remove the animation after it has completed so that its possible to manually resize the scatterviewitem w.Completed += (s, e) => svi.BeginAnimation(ScatterViewItem.WidthProperty, null); h.Completed += (s, e) => svi.BeginAnimation(ScatterViewItem.HeightProperty, null); // Set the size manually, otherwise once the animation is removed the size will revert back to the minimum size // Since animation has higher priority for DP's, this setting won't have effect until the animation is removed svi.Width = targetSize.Width; svi.Height = targetSize.Height; svi.BeginAnimation(ScatterViewItem.WidthProperty, w); svi.BeginAnimation(ScatterViewItem.HeightProperty, h); svi.BeginAnimation(ScatterViewItem.OpacityProperty, o); } }
public static void RunScaleAnimation(FrameworkElement e) { var storyboard = new Storyboard(); var easeOut = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.3 }; var startHeight = e.ActualHeight; var startWidth = e.ActualWidth; var growAnimationHOut = new DoubleAnimation(startHeight, startHeight * 1.05, TimeSpan.FromMilliseconds(70)) { AutoReverse = true }; var growAnimationWOut = new DoubleAnimation(startWidth, startWidth * 1.05, TimeSpan.FromMilliseconds(70)) { AutoReverse = true }; growAnimationHOut.EasingFunction = easeOut; growAnimationWOut.EasingFunction = easeOut; storyboard.Children.Add(growAnimationHOut); storyboard.Children.Add(growAnimationWOut); //remove the events after completed to ensure that the ScatterViewItem is resizable again growAnimationWOut.Completed += delegate { e.BeginAnimation(FrameworkElement.WidthProperty, null); }; growAnimationHOut.Completed += delegate { e.BeginAnimation(FrameworkElement.HeightProperty, null); }; Storyboard.SetTargetProperty(growAnimationWOut, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetProperty(growAnimationHOut, new PropertyPath(FrameworkElement.HeightProperty)); e.BeginStoryboard(storyboard); }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="whenDone">(optional) A callback that will be called when the animation has completed.</param> private AnimationTimeline CreateAnimation(double from, double to, EventHandler whenDone = null) { IEasingFunction ease = new BackEase { Amplitude = 0.5, EasingMode = EasingMode.EaseOut }; var duration = new Duration(TimeSpan.FromSeconds(0.8)); var anim = new DoubleAnimation(from, to, duration) { EasingFunction = ease }; if (whenDone != null) anim.Completed += whenDone; anim.Freeze(); return anim; }
private void InitStoryboard() { BackEase be = new BackEase(); be.EasingMode = EasingMode.EaseOut; DoubleAnimation daCollapsed = new DoubleAnimation(0, dur); Storyboard.SetTarget(daCollapsed, cpExpandSite); Storyboard.SetTargetProperty(daCollapsed, new PropertyPath(Control.HeightProperty)); sbCollapsed = new Storyboard(); sbCollapsed.Children.Add(daCollapsed); DoubleAnimation daExpanded = new DoubleAnimation(totalHeight, dur); //daExpanded.EasingFunction = be; Storyboard.SetTarget(daExpanded, cpExpandSite); Storyboard.SetTargetProperty(daExpanded, new PropertyPath(Control.HeightProperty)); sbExpanded = new Storyboard(); sbExpanded.Children.Add(daExpanded); }
private IEasingFunction ObterFuncaoDaAnimacao() { EasingFunctionBase funcaoDaAnimacao = null; switch (FuncaoDaAnimacao.SelectedValue.ToString()) { case "BackEase": funcaoDaAnimacao = new BackEase(); break; case "BounceEase": funcaoDaAnimacao = new BounceEase(); break; case "CircleEase": funcaoDaAnimacao = new CircleEase(); break; case "CubicEase": funcaoDaAnimacao = new CubicEase(); break; case "ElasticEase": funcaoDaAnimacao = new ElasticEase(); break; case "ExponentialEase": funcaoDaAnimacao = new ExponentialEase(); break; case "PowerEase": funcaoDaAnimacao = new PowerEase(); break; case "QuadraticEase": funcaoDaAnimacao = new QuadraticEase(); break; case "QuarticEase": funcaoDaAnimacao = new QuarticEase(); break; case "QuinticEase": funcaoDaAnimacao = new QuinticEase(); break; case "SineEase": funcaoDaAnimacao = new SineEase(); break; } funcaoDaAnimacao.EasingMode = ObterModoDaAnimacao(); return funcaoDaAnimacao; }
/// <summary> /// Führt die Animation für beide Contents aus /// </summary> private void _BeginAnimateContentReplacement() { OldContentTransform = new TranslateTransform(); NewContentTransform = new TranslateTransform(); _paintArea.Visibility = Visibility.Visible; _paintArea.RenderTransform = OldContentTransform; _mainContent.RenderTransform = NewContentTransform; IEasingFunction ease = new BackEase { Amplitude = 0.5, EasingMode = EasingMode.EaseInOut }; NewContentTransform.BeginAnimation(TranslateTransform.XProperty, AnimateLib.CreateAnimation(this.ActualWidth, 0, 0, 1, ease)); OldContentTransform.BeginAnimation(TranslateTransform.XProperty, AnimateLib.CreateAnimation(0, -this.ActualWidth, 0, 1, ease, (s, e) => { _paintArea.Visibility = Visibility.Hidden; })); }
private void AnimateExit() { var svi = GuiHelpers.GetParentObject<ScatterViewItem>(this, false); if (svi != null) { IEasingFunction ease = new BackEase {EasingMode = EasingMode.EaseOut, Amplitude = 0.3}; var duration = new Duration(TimeSpan.FromMilliseconds(500)); var w = new DoubleAnimation(0.0, duration) {EasingFunction = ease}; var h = new DoubleAnimation(0.0, duration) {EasingFunction = ease}; var o = new DoubleAnimation(0.0, duration); svi.BeginAnimation(ScatterViewItem.WidthProperty, w); svi.BeginAnimation(ScatterViewItem.HeightProperty, h); svi.BeginAnimation(ScatterViewItem.OpacityProperty, o); } }
void TranslateAnimation(FrameworkElement fe, double offset, bool vertical=false) { var translated = fe.RenderTransform as TranslateTransform; if (!fe.RenderTransform.HasAnimatedProperties) { var translate = new TranslateTransform(); fe.RenderTransform = translate; } var storyboard = new Storyboard(); var animation = new DoubleAnimation(); /* if (offset == 0) { // animation.From = translated.X; } */ animation.To = offset; animation.Duration = new Duration(TimeSpan.FromSeconds(1)); var ease = new BackEase(); ease.EasingMode = EasingMode.EaseInOut; ease.Amplitude = 1; animation.EasingFunction = ease; PropertyPath path; if (vertical) { path = new PropertyPath("(RenderTransform).(TranslateTransform.Y)"); } else { path = new PropertyPath("(RenderTransform).(TranslateTransform.X)"); } Storyboard.SetTargetProperty(animation, path); storyboard.Children.Add(animation); fe.BeginStoryboard(storyboard); }
public void PlayAnimation(bool random = true) { if (!AllowAnimation) return; var storyboard = new Storyboard(); var pa = new Point3DAnimation() { Duration = TimeSpan.FromMilliseconds(600), To = new Point3D(0, 0, 800) }; Storyboard.SetTarget(pa, this); Storyboard.SetTargetProperty(pa, new PropertyPath(CameraPoint3DProperty)); storyboard.Children.Add(pa); var aa = new Vector3DAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(1500)), To = AnimationHelper.GetNextVector3D() }; Storyboard.SetTarget(aa, this); Storyboard.SetTargetProperty(aa, new PropertyPath(AxisProperty)); storyboard.Children.Add(aa); angle += AnimationHelper.GetNextBool() ? 360d : -360d; //angle += AnimationHelper.GetNextAngle(); var da = new DoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(3000)), To = angle }; Storyboard.SetTarget(da, this); Storyboard.SetTargetProperty(da, new PropertyPath(AngleProperty)); storyboard.Children.Add(da); var paEnd = new Point3DAnimation() { Duration = TimeSpan.FromMilliseconds(600), To = new Point3D(0, 0, 500), BeginTime = TimeSpan.FromMilliseconds(2400) }; Storyboard.SetTarget(paEnd, this); Storyboard.SetTargetProperty(paEnd, new PropertyPath(CameraPoint3DProperty)); storyboard.Children.Add(paEnd); var aaEnd = new Vector3DAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(1500)), To = new Vector3D(0, 1, 0), BeginTime = TimeSpan.FromMilliseconds(1500) }; Storyboard.SetTarget(aaEnd, this); Storyboard.SetTargetProperty(aaEnd, new PropertyPath(AxisProperty)); storyboard.Children.Add(aaEnd); if (random) { da.EasingFunction = AnimationHelper.GetEasingFunction(); pa.EasingFunction = AnimationHelper.GetEasingFunction(); paEnd.EasingFunction = AnimationHelper.GetEasingFunction(); aa.EasingFunction = AnimationHelper.GetEasingFunction(); aaEnd.EasingFunction = AnimationHelper.GetEasingFunction(); } else { var easing = new BackEase() {EasingMode = EasingMode.EaseInOut, Amplitude = 0.8}; da.EasingFunction = easing; pa.EasingFunction = easing; paEnd.EasingFunction = easing; aa.EasingFunction = easing; aaEnd.EasingFunction = easing; } storyboard.Begin(this); }
internal void Animate(Point from, Point to, bool movedEvent) { Canvas.SetZIndex(this, 1); TimeSpan duration = TimeSpan.FromMilliseconds(250); var backEase = new BackEase {Amplitude = 0.2, EasingMode = EasingMode.EaseOut}; var x = new DoubleAnimation { Duration = duration, From = from.X, To = to.X, EasingFunction = backEase }; Storyboard.SetTargetProperty(x, new PropertyPath(Canvas.LeftProperty)); Storyboard.SetTarget(x, this); var y = new DoubleAnimation { Duration = duration, From = from.Y, To = to.Y, EasingFunction = backEase }; Storyboard.SetTargetProperty(y, new PropertyPath(Canvas.TopProperty)); Storyboard.SetTarget(y, this); var storyboard = new Storyboard(); storyboard.Children.Add(y); storyboard.Children.Add(x); if (movedEvent) { storyboard.Completed += MoveCompleted; } else { storyboard.Completed += MoveCompletedSilent; } storyboard.Begin(); }
public void NavigateToPage(int index,bool isAnimated) { OnPageNavigating(); _isAnimating = isAnimated; int currentChildIndex = 0; double animationDelaySeconds = NavigationAnimationDuration.TimeSpan.TotalSeconds * 0.008; foreach (var page in _pages) { TimeSpan animationDelay = TimeSpan.FromSeconds(0); foreach (var row in page.Rows) { foreach (var child in row.Children) { bool isDragMoving = AllowDragMoveChild && _isMouseDownOnChild && child.Equals(_mouseClickedChild); if (isDragMoving) { ++currentChildIndex; continue; } TranslateTransform tt = child.RenderTransform as TranslateTransform; if (isAnimated) { DoubleAnimation d = new DoubleAnimation(); BackEase bEase = new BackEase(); bEase.EasingMode = EasingMode.EaseOut; bEase.Amplitude = 0.3; d.EasingFunction = bEase; d.Duration = NavigationAnimationDuration; d.From = tt.X; d.To = -index * Width; d.BeginTime = animationDelay; d.Completed += (s, e) => { if (++currentChildIndex == InternalChildren.Count) { _isAnimating = false; OnPageNavigated(); } }; tt.BeginAnimation(TranslateTransform.XProperty, d); animationDelay += TimeSpan.FromSeconds(animationDelaySeconds); } else { tt.X = -index * Width; } _currentPageIndex = index; } } } _dragMovedElements.Clear(); }
public void PlayAnimation(bool random = true) { var storyboard = new Storyboard(); var temp = AnimationHelper.GetNextInterval(1, 4); angel += AnimationHelper.GetNextBool() ? temp*90d : -temp*90d; var da = new DoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(1000 + 800 * temp)), To = angel }; storyboard.Children.Add(da); Storyboard.SetTarget(da, this); Storyboard.SetTargetProperty(da, new PropertyPath(AngleProperty)); var paStart = new Point3DAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(1000)), To = new Point3D(0, 0, 1000) }; storyboard.Children.Add(paStart); Storyboard.SetTarget(paStart, this); Storyboard.SetTargetProperty(paStart, new PropertyPath(CameraPoint3DProperty)); var color = new ColorAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(1000)), To = Color.FromArgb(0x11, 0, 0 ,0) }; storyboard.Children.Add(color); Storyboard.SetTarget(color, this); Storyboard.SetTargetProperty(color, new PropertyPath(MonthColorProperty)); var axis = new Vector3DAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(500 + 400 * temp)), To = AnimationHelper.GetNextVector3D() }; storyboard.Children.Add(axis); Storyboard.SetTarget(axis, this); Storyboard.SetTargetProperty(axis, new PropertyPath(AxisProperty)); var paEnd = new Point3DAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(1000)), To = new Point3D(0, 0, 560), BeginTime = TimeSpan.FromMilliseconds(800 * temp) }; storyboard.Children.Add(paEnd); Storyboard.SetTarget(paEnd, this); Storyboard.SetTargetProperty(paEnd, new PropertyPath(CameraPoint3DProperty)); var colorBack = new ColorAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(1000)), To = Colors.Transparent, BeginTime = TimeSpan.FromMilliseconds(800 * temp) }; storyboard.Children.Add(colorBack); Storyboard.SetTarget(colorBack, this); Storyboard.SetTargetProperty(colorBack, new PropertyPath(MonthColorProperty)); var axisBack = new Vector3DAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(500 + 400 * temp)), To = new Vector3D(0, 1, 0), BeginTime = TimeSpan.FromMilliseconds(500 + 400 * temp) }; storyboard.Children.Add(axisBack); Storyboard.SetTarget(axisBack, this); Storyboard.SetTargetProperty(axisBack, new PropertyPath(AxisProperty)); if (random) { da.EasingFunction = AnimationHelper.GetEasingFunction(); paStart.EasingFunction = AnimationHelper.GetEasingFunction(); color.EasingFunction = paStart.EasingFunction; paEnd.EasingFunction = AnimationHelper.GetEasingFunction(); colorBack.EasingFunction = paEnd.EasingFunction; } else { var e = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 }; da.EasingFunction = e; paStart.EasingFunction = e; paEnd.EasingFunction = e; color.EasingFunction = e; colorBack.EasingFunction = e; } storyboard.Begin(); }
private static void OnTimerTick(RadCartesianChart chart) { CameraInfo cameraInfo = GetOrCreateCameraInfo(chart); double durationInSeconds = 1.5; Point targetOffset = new Point(100, -75); TimeSpan timeSpan = DateTime.Now - cameraInfo.initialAnimationDateTime; if (durationInSeconds < timeSpan.TotalSeconds) { cameraInfo.initialAnimationTimer.Stop(); cameraInfo.initialAnimationTimer = null; return; } double progress = timeSpan.TotalSeconds / durationInSeconds; EasingFunctionBase ease = new BackEase { EasingMode = EasingMode.EaseIn }; double easedProgress = ease.Ease(progress); double hOffset = easedProgress * targetOffset.X; ease = new CubicEase { EasingMode = EasingMode.EaseInOut }; easedProgress = ease.Ease(progress); double vOffset = easedProgress * targetOffset.Y; MoveCamera(chart, new Point(hOffset, vOffset)); }
public static PlotElementAnimation CreateAnimation(AnimationTransform transform, AnimationOrigin origin, Easing easing, bool indexDelay) { var sb = new Storyboard(); var duration = new Duration(TimeSpan.FromSeconds(0.5)); var style = new Style(); style.TargetType = typeof(PlotElement); style.Setters.Add(new Setter(PlotElement.OpacityProperty, 0.0)); if (transform == AnimationTransform.Scale) style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new ScaleTransform() { ScaleX = 0, ScaleY = 0 })); else if (transform == AnimationTransform.Rotation) style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new RotateTransform() { Angle = 180 })); var point = new Point(0.5, 0.5); switch (origin) { case AnimationOrigin.Bottom: point = new Point(0.5, 2); break; case AnimationOrigin.Top: point = new Point(0.5, -2); break; case AnimationOrigin.Left: point = new Point(-2, 0.5); break; case AnimationOrigin.Right: point = new Point(2, 0.5); break; case AnimationOrigin.TopLeft: point = new Point(2, -2); break; case AnimationOrigin.TopRight: point = new Point(-2, -2); break; case AnimationOrigin.BottomLeft: point = new Point(2, 2); break; case AnimationOrigin.BottomRight: point = new Point(-2, 2); break; default: break; } style.Setters.Add(new Setter(PlotElement.RenderTransformOriginProperty, point)); var da = new DoubleAnimation() { From = 0, To = 1, Duration = duration }; Storyboard.SetTargetProperty(da, new PropertyPath("Opacity")); sb.Children.Add(da); if (transform == AnimationTransform.Scale) { var da2 = new DoubleAnimation() { From = 0, To = 1, Duration = duration }; Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).ScaleX")); var da3 = new DoubleAnimation() { From = 0, To = 1, Duration = duration }; Storyboard.SetTargetProperty(da3, new PropertyPath("(RenderTransform).ScaleY")); sb.Children.Add(da2); sb.Children.Add(da3); } else if (transform == AnimationTransform.Rotation) { var da2 = new DoubleAnimation() { To = 0, Duration = duration }; Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).Angle")); sb.Children.Add(da2); } if (indexDelay) { foreach (var anim in sb.Children) PlotElementAnimation.SetIndexDelay(anim, 0.5); } #if CLR40 if (easing != Easing.None) { IEasingFunction ef = null; switch (easing) { case Easing.BackEase: ef = new BackEase(); break; case Easing.BounceEase: ef = new BounceEase(); break; case Easing.CircleEase: ef = new CircleEase(); break; case Easing.CubicEase: ef = new CubicEase(); break; case Easing.ElasticEase: ef = new ElasticEase(); break; case Easing.ExponentialEase: ef = new ExponentialEase(); break; case Easing.PowerEase: ef = new PowerEase(); break; case Easing.QuadraticEase: ef = new QuadraticEase(); break; case Easing.QuarticEase: ef = new QuarticEase(); break; case Easing.QuinticEase: ef = new QuinticEase(); break; case Easing.SineEase: ef = new SineEase(); break; default: break; } foreach (DoubleAnimation anim in sb.Children) anim.EasingFunction = ef; } #endif return new PlotElementAnimation() { Storyboard = sb, SymbolStyle = style }; }