private void ZoomOut(FrameworkElement switchOut, FrameworkElement switchIn) { QuarticEase Ease = new QuarticEase(); Ease.EasingMode = EasingMode.EaseIn; centerX = switchOut.ActualWidth / 2; centerY = switchOut.ActualHeight / 2; ScaleTransform scaleOut = (ScaleTransform)GetRenderTransform(switchOut, typeof(ScaleTransform)); scaleOut.CenterX = centerX; scaleOut.CenterY = centerY; scaleOut.ScaleX = scaleOut.ScaleY = 1; DoubleAnimation scaleOutAnim2 = new DoubleAnimation(0.9, AnimationDuration, FillBehavior.Stop); scaleOutAnim2.Completed += scaleOut2Anim_Completed; scaleOutAnim2.EasingFunction = Ease; DoubleAnimation opacityOutAnim = new DoubleAnimation(1, 0, AnimationDuration, FillBehavior.Stop); opacityOutAnim.EasingFunction = Ease; _switchOut.BeginAnimation(FrameworkElement.OpacityProperty, opacityOutAnim); scaleOut.BeginAnimation(ScaleTransform.ScaleXProperty, scaleOutAnim2); scaleOut.BeginAnimation(ScaleTransform.ScaleYProperty, scaleOutAnim2); }
/// <summary> /// Initializes a new instance of the AnimateOrientationChangesFrame class. /// </summary> public AnimateOrientationChangesFrame() { // Find existing "offset transform" and take it over (if possible) to support SIP raise/lower var transformGroup = new TransformGroup(); var oldTransformGroup = RenderTransform as TransformGroup; if ((null != oldTransformGroup) && (3 <= oldTransformGroup.Children.Count)) { var offsetTransform = oldTransformGroup.Children[0] as TranslateTransform; if (null != offsetTransform) { transformGroup.Children.Add(offsetTransform); } } // Add custom transforms transformGroup.Children.Add(_rotateTransform); transformGroup.Children.Add(_translateTransform); // Replace existing transform(s) RenderTransform = transformGroup; // Set up animation _progressAnimation.From = 0; _progressAnimation.To = 1; Storyboard.SetTarget(_progressAnimation, this); Storyboard.SetTargetProperty(_progressAnimation, new PropertyPath("Progress")); _progressStoryboard.Children.Add(_progressAnimation); // Initialize variables EasingFunction = new QuarticEase(); // Initialized here to avoid a single shared instance // Hook events SizeChanged += new SizeChangedEventHandler(HandleSizeChanged); OrientationChanged += new EventHandler <OrientationChangedEventArgs>(HandleOrientationChanged); }
private void ZoomOut() { QuarticEase Ease = new QuarticEase(); Ease.EasingMode = EasingMode.EaseOut; ScaleTransform scaleIn = (ScaleTransform)GetRenderTransform(_switchIn, typeof(ScaleTransform)); scaleIn.CenterX = centerX; scaleIn.CenterY = centerY; scaleIn.ScaleX = scaleIn.ScaleY = 1; DoubleAnimation scaleOutAnim = new DoubleAnimation(0.9, AnimationDuration, FillBehavior.Stop); scaleOutAnim.Completed += scaleOutAnim_Completed; scaleOutAnim.EasingFunction = Ease; _switchIn.Visibility = Visibility.Visible; DoubleAnimation opacityInAnim = new DoubleAnimation(1, 0, AnimationDuration, FillBehavior.Stop); opacityInAnim.EasingFunction = Ease; scaleIn.BeginAnimation(ScaleTransform.ScaleXProperty, scaleOutAnim); scaleIn.BeginAnimation(ScaleTransform.ScaleYProperty, scaleOutAnim); _switchIn.BeginAnimation(FrameworkElement.OpacityProperty, opacityInAnim); }
//private List<Storyboard> _slideTransitions; //public List<Storyboard> SlideTransitions //{ // get // { // if (this._slideTransitions == null) this._slideTransitions = new List<Storyboard>(); // return this._slideTransitions; // } // set // { // this._slideTransitions = value; // } //} // An animation that restores the slider to the central, 'relaxed' position void SlideToCentralMeasurement() { this.PendingSlide = Slide.None; double finalX = this.SliderRestTranslateX; double initialX = this.sliderTransform.TranslateX; this.CancelHighlight(); this.SlideStoryBoard.Stop(); this.SlideStoryBoard.Children.Clear(); //Dispatcher.BeginInvoke(() => //{ IEasingFunction easing = new QuarticEase() { EasingMode = EasingMode.EaseOut }; // Animate back to rest position DoubleAnimation xTransAnim = new DoubleAnimation() { From = initialX, To = finalX, Duration = TimeSpan.FromMilliseconds(750), EasingFunction = easing, }; Storyboard.SetTarget(xTransAnim, this.sliderTransform); Storyboard.SetTargetProperty(xTransAnim, new PropertyPath(CompositeTransform.TranslateXProperty)); this.SlideStoryBoard.Children.Add(xTransAnim); this.SlideStoryBoard.Begin(); //}); }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Create a DoubleAnimation to animate the width of the button. animInit = new DoubleAnimation(); animInit.From = 0; animInit.To = 100; QuarticEase easingFunction = new QuarticEase(); easingFunction.EasingMode = EasingMode.EaseInOut; animInit.EasingFunction = easingFunction; animInit.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animMouseEnter = new DoubleAnimation(); animMouseEnter.From = 100; animMouseEnter.To = 150; animMouseEnter.EasingFunction = easingFunction; animMouseEnter.Duration = new Duration(TimeSpan.FromMilliseconds(400)); animMouseLeave = new DoubleAnimation(); //animMouseLeave.From = 100; animMouseLeave.To = 100; animMouseLeave.EasingFunction = easingFunction; animMouseLeave.Duration = new Duration(TimeSpan.FromMilliseconds(400)); AddButton("L1"); AddButton("L2"); AddButton("L3"); }
private void rightAnim1_Completed(object sender, EventArgs e) { _image.Visibility = Visibility.Hidden; _image.ApplyAnimationClock(FrameworkElement.OpacityProperty, null); GetRenderTransform(_image, typeof(TranslateTransform)).ApplyAnimationClock(TranslateTransform.XProperty, null); //_image.ApplyAnimationClock(FrameworkElement.MarginProperty, null); QuarticEase Ease = new QuarticEase(); Ease.EasingMode = EasingMode.EaseOut; _grid.Visibility = Visibility.Visible; TranslateTransform gridTransform = (TranslateTransform)GetRenderTransform(_grid, typeof(TranslateTransform)); DoubleAnimation leftAnim2 = new DoubleAnimation(50, 0, AnimationDuration, FillBehavior.Stop); leftAnim2.EasingFunction = Ease; leftAnim2.Completed += anim_Completed; //ThicknessAnimation leftAnim2 = new ThicknessAnimation(new Thickness(60, 0, -60, 0), new Thickness(0), AnimationDuration, FillBehavior.Stop); //leftAnim2.EasingFunction = Ease; //leftAnim2.Completed += anim_Completed; DoubleAnimation opac = new DoubleAnimation(0, 1, AnimationDuration, FillBehavior.Stop); opac.EasingFunction = Ease; _grid.BeginAnimation(FrameworkElement.OpacityProperty, opac); gridTransform.BeginAnimation(TranslateTransform.XProperty, leftAnim2); //_grid.BeginAnimation(FrameworkElement.MarginProperty, leftAnim2); }
static Animations() { TypicalDuration = TimeSpan.FromMilliseconds((double)AnimationSpeed.Normal); TypicalEasing = new QuarticEase { EasingMode = EasingMode.EaseOut }; TypicalEasing.Freeze(); }
internal static EasingFunctionBase GetEase(this AnimationSettings settings) { EasingFunctionBase ease; switch (settings.Easing) { case EasingType.Back: ease = new BackEase(); break; case EasingType.Bounce: ease = new BounceEase(); break; case EasingType.Circle: ease = new CircleEase(); break; case EasingType.Cubic: ease = new CubicEase(); break; case EasingType.Elastic: ease = new ElasticEase(); break; case EasingType.Linear: ease = null; break; case EasingType.Quadratic: ease = new QuadraticEase(); break; case EasingType.Quartic: ease = new QuarticEase(); break; case EasingType.Quintic: ease = new QuinticEase(); break; case EasingType.Sine: ease = new SineEase(); break; default: ease = new CubicEase(); break; } if (ease != null) { ease.EasingMode = settings.EasingMode; } return(ease); }
public void ShowAnswer() { FrameworkElement answerContainer = ViewHelpers.FindSiblingByName(this, this.AnswerContainerName); Dispatcher.BeginInvoke(() => { IEasingFunction easeOut = new QuarticEase() { EasingMode = EasingMode.EaseOut }; Storyboard sb = new Storyboard(); // Animate the height DoubleAnimation heightAnim = new DoubleAnimation() { From = 0, To = this.AnswerContainerHeight, Duration = TimeSpan.FromMilliseconds(750), EasingFunction = easeOut, }; Storyboard.SetTargetProperty(heightAnim, new PropertyPath(FrameworkElement.HeightProperty)); Storyboard.SetTarget(heightAnim, answerContainer); sb.Children.Add(heightAnim); // 'Animate' the visibility ObjectAnimationUsingKeyFrames visibilityAnim = new ObjectAnimationUsingKeyFrames(); visibilityAnim.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(0), Value = Visibility.Visible, }); Storyboard.SetTarget(visibilityAnim, answerContainer); Storyboard.SetTargetProperty(visibilityAnim, new PropertyPath(FrameworkElement.VisibilityProperty)); sb.Children.Add(visibilityAnim); // Add child animations //var children = ViewHelpers.GetChildren(answerContainer); //double offset = 0; //foreach (FrameworkElement child in children) //{ // offset += 100; // DoubleAnimation rotAnim = new DoubleAnimation() // { // From = 90, // To = 0, // Duration = TimeSpan.FromMilliseconds(1000), // EasingFunction = easeOut, // BeginTime = TimeSpan.FromMilliseconds(offset), // }; // Storyboard.SetTargetProperty(rotAnim, new PropertyPath(PlaneProjection.RotationXProperty)); // Storyboard.SetTarget(rotAnim, child); // sb.Children.Add(rotAnim); //} sb.Begin(); }); }
/// <summary> /// Obtiene una función quartic /// </summary> private QuarticEase GetQuarticeEase(QuarticEaseModel quarticEase) { QuarticEase ease = new QuarticEase(); // Asigna las propiedades ease.EasingMode = ConvertEaseMode(quarticEase.EaseMode); // Devuelve la función return(ease); }
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); }
private void ChengeLock(bool started) { LockImage2.Visibility = Visibility.Visible; DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.From = started?0d:1d; doubleAnimation.To = !started ? 0d : 1d; doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(1000)); QuarticEase easingFunction = new QuarticEase(); easingFunction.EasingMode = EasingMode.EaseInOut; doubleAnimation.EasingFunction = easingFunction; LockImage2.BeginAnimation(Image.OpacityProperty, doubleAnimation); }
private void CreateWindowAnimation() { DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.From = 50; doubleAnimation.To = 400; doubleAnimation.Duration = TimeSpan.FromSeconds(0.5); QuarticEase quarticEase = new QuarticEase(); quarticEase.EasingMode = EasingMode.EaseOut; doubleAnimation.EasingFunction = quarticEase; teamInfoGrid.BeginAnimation(HeightProperty, doubleAnimation); }
private static void SlideLeft(FrameworkElement slideElement, Image image) { QuarticEase Ease = new QuarticEase(); Ease.EasingMode = EasingMode.EaseIn; ThicknessAnimation leftAnim1 = new ThicknessAnimation(new Thickness(0), new Thickness(60, 0, -60, 0), AnimationDuration, FillBehavior.Stop); leftAnim1.EasingFunction = Ease; leftAnim1.Completed += (sender, e) => { image.Visibility = Visibility.Hidden; image.ApplyAnimationClock(FrameworkElement.OpacityProperty, null); image.ApplyAnimationClock(FrameworkElement.MarginProperty, null); QuarticEase Ease2 = new QuarticEase(); Ease2.EasingMode = EasingMode.EaseOut; slideElement.Visibility = Visibility.Visible; ThicknessAnimation leftAnim2 = new ThicknessAnimation(new Thickness(-60, 0, 60, 0), new Thickness(0), AnimationDuration, FillBehavior.Stop); leftAnim2.EasingFunction = Ease2; leftAnim2.Completed += (_sender, _e) => { slideElement.ApplyAnimationClock(FrameworkElement.OpacityProperty, null); slideElement.ApplyAnimationClock(FrameworkElement.MarginProperty, null); }; DoubleAnimation opac2 = new DoubleAnimation(0, 1, AnimationDuration, FillBehavior.Stop); opac2.EasingFunction = Ease2; slideElement.BeginAnimation(FrameworkElement.OpacityProperty, opac2); slideElement.BeginAnimation(FrameworkElement.MarginProperty, leftAnim2); }; DoubleAnimation opac = new DoubleAnimation(1, 0, AnimationDuration, FillBehavior.Stop); opac.EasingFunction = Ease; image.BeginAnimation(FrameworkElement.OpacityProperty, opac); image.BeginAnimation(FrameworkElement.MarginProperty, leftAnim1); }
/// <summary> /// 绘制进度条的圆弧 /// </summary> void DrawAngle() { double angle = 0.1; double percent = 0; if (this.Min == this.Max) { angle = 0.1; percent = 0; } else { angle = (this.Progress - this.Min) / (this.Max - this.Min) * 360; // 计算圆弧绘制的弧度 if (angle <= 0) { angle = 0.1; } percent = (this.Progress - this.Min) / (this.Max - this.Min) * 100; // 计算百分比 if (percent <= 0) { percent = 0; } } // 绘制圆弧用到的动画 QuarticEase ease = new QuarticEase() { EasingMode = EasingMode.EaseOut }; DoubleAnimation animation = new DoubleAnimation(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animation.To = angle; animation.EasingFunction = ease; animationclock = animation.CreateClock(); animationclock.Completed += animationclock_Completed; // 绘制圆弧 this.ProgressIndicator.ApplyAnimationClock(Arc.EndAngleProperty, animationclock, HandoffBehavior.SnapshotAndReplace); this.txt_ProgressValue.Text = string.Format("{0}%", percent.ToString("F1")); }
public MainWindow() { InitializeComponent(); RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant); mainDispatcher = this.Dispatcher; DataContext = vm; GridOpeningAnim.Duration = TimeSpan.FromSeconds(duration); GridClosingAnim.Duration = TimeSpan.FromSeconds(duration); GridOpeningAnim.From = new GridLength(0, GridUnitType.Star); GridOpeningAnim.To = new GridLength(563, GridUnitType.Star); GridClosingAnim.From = new GridLength(563, GridUnitType.Star); GridClosingAnim.To = new GridLength(0, GridUnitType.Star); QuarticEase easer = new QuarticEase(); easer.EasingMode = EasingMode.EaseOut; GridOpeningAnim.EasingFunction = easer; GridClosingAnim.EasingFunction = easer; WindowOpeningAnim.EasingFunction = easer; WindowClosingAnim.EasingFunction = easer; SaveMessageClose.EasingFunction = easer; SaveMessageOpen.EasingFunction = easer; ThisWindow.BeginAnimation(Window.WidthProperty, WindowClosingAnim); SaveColumn.BeginAnimation(ColumnDefinition.WidthProperty, GridClosingAnim); SuccessfulSaveMessage.RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, SaveMessageClose); FailedSaveMessage.RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, SaveMessageClose); vm.PropertyChanged += (source, args) => { if (args.PropertyName == "SaveSuccess") { mainDispatcher.BeginInvoke(new Action(() => ChangeSaveMessageVisibility(vm.SaveSuccess))); } }; }
private void SlideRight() { QuarticEase Ease = new QuarticEase(); Ease.EasingMode = EasingMode.EaseIn; TranslateTransform translate = (TranslateTransform)GetRenderTransform(_image, typeof(TranslateTransform)); DoubleAnimation rightAnim1 = new DoubleAnimation(0, -50, AnimationDuration, FillBehavior.Stop); //ThicknessAnimation rightAnim1 = new ThicknessAnimation(new Thickness(0), new Thickness(-50, 0, 50, 0), AnimationDuration, FillBehavior.Stop); rightAnim1.EasingFunction = Ease; rightAnim1.Completed += rightAnim1_Completed; DoubleAnimation opac = new DoubleAnimation(1, 0, AnimationDuration, FillBehavior.Stop); opac.EasingFunction = Ease; _image.BeginAnimation(FrameworkElement.OpacityProperty, opac); translate.BeginAnimation(TranslateTransform.XProperty, rightAnim1); //_image.BeginAnimation(FrameworkElement.MarginProperty, rightAnim1); }
///////////////////////////////////////////////////////////////////////////////////////////////////// #region NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes the easing functions. /// </summary> private void InitializeEasingFunctions() { var quarticEase = new QuarticEase(); EasingFunctions.Add(new BackEase()); EasingFunctions.Add(new BounceEase()); EasingFunctions.Add(new CircleEase()); EasingFunctions.Add(new CubicEase()); EasingFunctions.Add(new ElasticEase()); EasingFunctions.Add(new ExponentialEase()); EasingFunctions.Add(new PowerEase()); EasingFunctions.Add(new QuadraticEase()); EasingFunctions.Add(quarticEase); EasingFunctions.Add(new QuinticEase()); EasingFunctions.Add(new SineEase()); foreach (EasingFunctionBase easingFunction in EasingFunctions) { easingFunction.EasingMode = EasingMode.EaseOut; } SelectedEasingFunction = quarticEase; }
private void scaleOut2Anim_Completed(object sender, EventArgs e) { QuarticEase Ease = new QuarticEase(); Ease.EasingMode = EasingMode.EaseOut; _switchOut.Visibility = Visibility.Collapsed; _switchOut.ApplyAnimationClock(FrameworkElement.OpacityProperty, null); ScaleTransform scaleOut = (ScaleTransform)GetRenderTransform(_switchOut, typeof(ScaleTransform)); scaleOut.ApplyAnimationClock(ScaleTransform.ScaleXProperty, null); scaleOut.ApplyAnimationClock(ScaleTransform.ScaleYProperty, null); ScaleTransform scaleIn = (ScaleTransform)GetRenderTransform(_switchIn, typeof(ScaleTransform)); scaleIn.CenterX = centerX; scaleIn.CenterY = centerY; scaleIn.ScaleX = scaleIn.ScaleY = 1.1; DoubleAnimation scaleInAnim = new DoubleAnimation(1, AnimationDuration, FillBehavior.Stop); scaleInAnim.Completed += scaleInAnim_Completed; scaleInAnim.EasingFunction = Ease; _switchIn.Visibility = Visibility.Visible; DoubleAnimation opacityInAnim = new DoubleAnimation(0, 1, AnimationDuration, FillBehavior.Stop); // To do, or not to do opacityInAnim.EasingFunction = Ease; scaleIn.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnim); scaleIn.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnim); _switchIn.BeginAnimation(FrameworkElement.OpacityProperty, opacityInAnim); }
private static void SlideOutAnimation() { Backstage animBackstage = _animBackstage._backstage; animBackstage.IsHitTestVisible = false; animBackstage.PrepareToClose(); DoubleAnimation transformAnim = new DoubleAnimation(-animBackstage.PART_ItemsStackPanel.ActualWidth, AnimationHelpers.AnimationDuration, FillBehavior.Stop); transformAnim.Completed += transformAnim_Completed; QuarticEase ease = new QuarticEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation opacityAnim = new DoubleAnimation(0, AnimationHelpers.AnimationDuration, FillBehavior.Stop); transformAnim.EasingFunction = opacityAnim.EasingFunction = ease; animBackstage.clientGridTranslate.BeginAnimation(TranslateTransform.XProperty, transformAnim); animBackstage.PART_ContentScreenshot.BeginAnimation(OpacityProperty, opacityAnim); }
private void Animate() { double ToYValue = 0.0; double ToOpacityValue = 1.0; if (GraphTranslateTransform.Y < 80) { ToYValue = 150.0; ToOpacityValue = 0.0; } DoubleAnimation GraphSlideAnimation = new(ToYValue, TimeSpan.FromSeconds(0.4)) { EasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseInOut } }; DoubleAnimation GraphOpacityAnimation = new(ToOpacityValue, TimeSpan.FromSeconds(0.4)) { EasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseInOut } }; GraphTranslateTransform.BeginAnimation(TranslateTransform.YProperty, GraphSlideAnimation); HourlyGraph.BeginAnimation(OpacityProperty, GraphOpacityAnimation); }
public Fade(FrameworkElement element, FadeDirection direction, bool hideOnComplete = false, double transparentOpacity = 0, double opaqueOpacity = 1, bool useExistingValues = false) { _element = element; _direction = direction; _hideoncomplete = hideOnComplete; _transparentOpacity = transparentOpacity; _opaqueOpacity = opaqueOpacity; if (direction == FadeDirection.In) { QuarticEase ease = new QuarticEase(); ease.EasingMode = EasingMode.EaseIn; if (!useExistingValues) { DoubleAnimation anim = new DoubleAnimation(transparentOpacity, opaqueOpacity, AnimationDuration, FillBehavior.Stop); anim.EasingFunction = ease; anim.Completed += anim_Completed; if (!(element is Window)) { element.Visibility = Visibility.Visible; } element.BeginAnimation(FrameworkElement.OpacityProperty, anim); } else { DoubleAnimation anim = new DoubleAnimation(opaqueOpacity, AnimationDuration); anim.EasingFunction = ease; if (!(element is Window)) { element.Visibility = Visibility.Visible; } element.BeginAnimation(FrameworkElement.OpacityProperty, anim); } } else { QuarticEase ease = new QuarticEase(); ease.EasingMode = EasingMode.EaseOut; if (!useExistingValues) { DoubleAnimation anim = new DoubleAnimation(opaqueOpacity, transparentOpacity, AnimationDuration, FillBehavior.Stop); anim.EasingFunction = ease; anim.Completed += anim_Completed; element.BeginAnimation(FrameworkElement.OpacityProperty, anim); } else { DoubleAnimation anim = new DoubleAnimation(transparentOpacity, AnimationDuration); anim.EasingFunction = ease; element.BeginAnimation(FrameworkElement.OpacityProperty, anim); } } }
object IValueConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { string functionEase = value as string; IEasingFunction returnFunctionEase = null; if (functionEase != null) { switch (functionEase) { case "ElasticEase": returnFunctionEase = new ElasticEase(); ((ElasticEase)returnFunctionEase).Springiness = 8; ((ElasticEase)returnFunctionEase).Oscillations = 10; break; case "BounceEase": returnFunctionEase = new BounceEase(); ((BounceEase)returnFunctionEase).Bounces = 8; ((BounceEase)returnFunctionEase).Bounciness = 2; break; case "BackEase": returnFunctionEase = new BackEase(); ((BackEase)returnFunctionEase).Amplitude = 1; break; case "CircleEase": returnFunctionEase = new CircleEase(); break; case "CubicEase": returnFunctionEase = new CubicEase(); break; case "ExponentialEase": returnFunctionEase = new ExponentialEase(); ((ExponentialEase)returnFunctionEase).Exponent = 5; break; case "PowerEase": returnFunctionEase = new PowerEase(); ((PowerEase)returnFunctionEase).Power = 5; break; case "QuadraticEase": returnFunctionEase = new QuadraticEase(); break; case "QuarticEase": returnFunctionEase = new QuarticEase(); break; case "QuinticEase": returnFunctionEase = new QuinticEase(); break; case "SineEase": returnFunctionEase = new SineEase(); break; } } return(returnFunctionEase); }
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 }); }
public void ExecuteAnimation2(List <int> vertices, double letterX, double letterY) { //List<int> temp = vertices.GetRange(1, vertices.Count - 1); Storyboard st = new Storyboard(); Storyboard st2 = new Storyboard(); st.FillBehavior = FillBehavior.HoldEnd; st2.FillBehavior = FillBehavior.HoldEnd; st.Children.Clear(); st2.Children.Clear(); Timeline t1; Timeline t2; Timeline t11; Timeline t22; SineEase ease = new SineEase(); ease.EasingMode = EasingMode.EaseOut; QuarticEase ease2 = new QuarticEase(); ease2.EasingMode = EasingMode.EaseOut; //foreach (int i in vertices) { t1 = new DoubleAnimation(); t1.SetValue(DoubleAnimation.ToProperty, letterX); Storyboard.SetTarget(t1, _pointViewList[vertices[0]]); Storyboard.SetTargetProperty(t1, new PropertyPath("PosX")); t1.Duration = new Duration(TimeSpan.FromSeconds(GameConstants.GAME_SPEED / 2)); t11 = new DoubleAnimation(); t11.SetValue(DoubleAnimation.ToProperty, letterY); Storyboard.SetTarget(t11, _pointViewList[vertices[0]]); Storyboard.SetTargetProperty(t11, new PropertyPath("PosY")); t11.Duration = new Duration(TimeSpan.FromSeconds(GameConstants.GAME_SPEED / 2)); t2 = new DoubleAnimation(); t2.SetValue(DoubleAnimation.ToProperty, letterX); Storyboard.SetTarget(t2, _pointViewList[vertices[0]]); Storyboard.SetTargetProperty(t2, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)")); t2.Duration = new Duration(TimeSpan.FromSeconds(GameConstants.GAME_SPEED / 2)); t22 = new DoubleAnimation(); t22.SetValue(DoubleAnimation.ToProperty, letterY); Storyboard.SetTarget(t22, _pointViewList[vertices[0]]); Storyboard.SetTargetProperty(t22, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)")); t22.Duration = new Duration(TimeSpan.FromSeconds(GameConstants.GAME_SPEED / 2)); (t1 as DoubleAnimation).EasingFunction = ease2; (t11 as DoubleAnimation).EasingFunction = ease2; (t2 as DoubleAnimation).EasingFunction = ease; (t22 as DoubleAnimation).EasingFunction = ease; st.Children.Add(t1); st.Children.Add(t11); st2.Children.Add(t2); st2.Children.Add(t22); //} _storyboards.Insert(0, st); _storyboards2.Insert(0, st2); }
public override EasingFunctionBase Create(DeterministicRandom random) { EasingFunctionBase easingFunction; EasingMode easingMode; int easingSwitch = random.Next(10); double amplitude1 = (double)random.NextDouble() * 10; double amplitude2 = (double)random.NextDouble() * 10; easingMode = random.NextEnum <EasingMode>(); switch (easingSwitch) { case 0: easingFunction = new BackEase() { EasingMode = easingMode, Amplitude = amplitude1 }; break; case 1: easingFunction = new BounceEase() { EasingMode = easingMode, Bounces = (int)amplitude1, Bounciness = amplitude2 }; break; case 2: easingFunction = new CircleEase() { EasingMode = easingMode }; break; case 3: easingFunction = new CubicEase() { EasingMode = easingMode }; break; case 4: easingFunction = new ElasticEase() { EasingMode = easingMode, Oscillations = (int)amplitude1, Springiness = amplitude2 }; break; case 5: easingFunction = new ExponentialEase() { EasingMode = easingMode, Exponent = amplitude1 }; break; case 6: easingFunction = new PowerEase() { EasingMode = easingMode, Power = amplitude1 }; break; case 7: easingFunction = new QuarticEase() { EasingMode = easingMode }; break; case 8: easingFunction = new SineEase() { EasingMode = easingMode }; break; default: return(null); } return(easingFunction); }
private void CreateWindowCloseAnimation() { CreateTransformGroup(); closeWindowStoryboard = new Storyboard(); var duration = TimeSpan.FromSeconds(1); if (WindowAnimationType == AnimationType.RightBottomScale) { //位移动画 var easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation translateXAnimation = new DoubleAnimation(); translateXAnimation.To = ScreenArea.Width; translateXAnimation.Duration = duration; //BackEase,QuarticEase translateXAnimation.EasingFunction = easingFunction; Storyboard.SetTarget(translateXAnimation, this); Storyboard.SetTargetProperty(translateXAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)")); DoubleAnimation translateYAnimation = new DoubleAnimation(); translateYAnimation.To = ScreenArea.Height; translateYAnimation.Duration = duration; translateYAnimation.EasingFunction = easingFunction; Storyboard.SetTarget(translateYAnimation, this); Storyboard.SetTargetProperty(translateYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)")); //缩放动画 var scaleEasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation scaleXAnimation = new DoubleAnimation(); scaleXAnimation.To = 0; scaleXAnimation.Duration = duration; //BackEase,QuarticEase scaleXAnimation.EasingFunction = scaleEasingFunction; Storyboard.SetTarget(scaleXAnimation, this); Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)")); DoubleAnimation scaleYAnimation = new DoubleAnimation(); scaleYAnimation.To = 0; scaleYAnimation.Duration = duration; scaleYAnimation.EasingFunction = scaleEasingFunction; Storyboard.SetTarget(scaleYAnimation, this); Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)")); closeWindowStoryboard.Children.Add(translateXAnimation); closeWindowStoryboard.Children.Add(translateYAnimation); closeWindowStoryboard.Children.Add(scaleXAnimation); closeWindowStoryboard.Children.Add(scaleYAnimation); } else if (WindowAnimationType == AnimationType.Opacity) { DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.From = 1; opacityAnimation.To = 0; opacityAnimation.Duration = duration; opacityAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseInOut }; Storyboard.SetTarget(opacityAnimation, this); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); closeWindowStoryboard.Children.Add(opacityAnimation); } else if (WindowAnimationType == AnimationType.Cool) { var container = Content as Grid; DoubleAnimationUsingKeyFrames scaleAnimation = new DoubleAnimationUsingKeyFrames(); scaleAnimation.AutoReverse = true; scaleAnimation.KeyFrames.Add( new LinearDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); scaleAnimation.KeyFrames.Add( new LinearDoubleKeyFrame(5, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.5)))); scaleAnimation.KeyFrames.Add( new LinearDoubleKeyFrame(18, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.6)))); DoubleAnimationUsingKeyFrames scaleAnimation2 = new DoubleAnimationUsingKeyFrames(); scaleAnimation2.AutoReverse = true; scaleAnimation2.KeyFrames.Add( new LinearDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); scaleAnimation2.KeyFrames.Add( new LinearDoubleKeyFrame(5, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.5)))); scaleAnimation2.KeyFrames.Add( new LinearDoubleKeyFrame(18, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.6)))); Storyboard.SetTarget(scaleAnimation, container); Storyboard.SetTarget(scaleAnimation2, container); Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); Storyboard.SetTargetProperty(scaleAnimation2, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); DoubleAnimation opacityAnimation2 = new DoubleAnimation(); opacityAnimation2.From = 1; opacityAnimation2.To = 0; opacityAnimation2.Duration = TimeSpan.FromSeconds(.8); opacityAnimation2.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseInOut }; Storyboard.SetTarget(opacityAnimation2, this); Storyboard.SetTargetProperty(opacityAnimation2, new PropertyPath(OpacityProperty)); closeWindowStoryboard.Children.Add(scaleAnimation); closeWindowStoryboard.Children.Add(scaleAnimation2); closeWindowStoryboard.Children.Add(opacityAnimation2); } }
private EasingFunctionBase createEasingFunction(EasingType easingType, EasingMode easingMode, double?param1 = null, int?param2 = null) { EasingFunctionBase easingFunctionBase = null; switch (easingType) { case EasingType.Sine: easingFunctionBase = new SineEase(); break; case EasingType.Cubic: easingFunctionBase = new CubicEase(); break; case EasingType.Quint: easingFunctionBase = new QuinticEase(); break; case EasingType.Circ: easingFunctionBase = new CircleEase(); break; case EasingType.Quad: easingFunctionBase = new QuadraticEase(); break; case EasingType.Quart: easingFunctionBase = new QuarticEase(); break; case EasingType.Elastic: easingFunctionBase = new ElasticEase { Springiness = param1.GetValueOrDefault(3.0), Oscillations = param2.GetValueOrDefault(3) }; break; case EasingType.Expo: easingFunctionBase = new ExponentialEase { Exponent = param1.GetValueOrDefault(2.0) }; break; case EasingType.Back: easingFunctionBase = new BackEase { Amplitude = param1.GetValueOrDefault(1.0) }; break; case EasingType.Bounce: easingFunctionBase = new BounceEase { Bounciness = param1.GetValueOrDefault(2.0), Bounces = param2.GetValueOrDefault(3) }; break; } if (easingFunctionBase != null) { easingFunctionBase.EasingMode = easingMode; } return(easingFunctionBase); }
private void EasingChanged() { if (cboEasingFunction.SelectedIndex == -1 || cboEasingMode.SelectedIndex == -1) { return; } storyboard.Stop(); EasingFunctionBase easingFunction = null; // 确定 Easing Function switch ((cboEasingFunction.SelectedItem as ComboBoxItem).Content.ToString()) { case "BackEase": // Amplitude - 幅度,必须大于等于 0,默认值 1 easingFunction = new BackEase() { Amplitude = 1 }; break; case "BounceEase": // Bounces - 弹跳次数,必须大于等于 0,默认值 3 // Bounciness - 弹跳程度,必须是正数,默认值 2 easingFunction = new BounceEase() { Bounces = 3, Bounciness = 2 }; break; case "CircleEase": easingFunction = new CircleEase(); break; case "CubicEase": easingFunction = new CubicEase(); break; case "ElasticEase": // Oscillations - 来回滑动的次数,必须大于等于 0,默认值 3 // Springiness - 弹簧的弹度,必须是正数,默认值 3 easingFunction = new ElasticEase() { Oscillations = 3, Springiness = 3 }; break; case "ExponentialEase": easingFunction = new ExponentialEase(); break; case "PowerEase": easingFunction = new PowerEase(); break; case "QuadraticEase": easingFunction = new QuadraticEase(); break; case "QuarticEase": easingFunction = new QuarticEase(); break; case "QuinticEase": easingFunction = new QuinticEase(); break; case "SineEase": easingFunction = new SineEase(); break; default: break; } // 确定 Easing Mode switch ((cboEasingMode.SelectedItem as ComboBoxItem).Content.ToString()) { case "EaseIn": // 渐进 easingFunction.EasingMode = EasingMode.EaseIn; break; case "EaseOut": // 渐出(默认值) easingFunction.EasingMode = EasingMode.EaseOut; break; case "EaseInOut": // 前半段渐进,后半段渐出 easingFunction.EasingMode = EasingMode.EaseInOut; break; default: break; } // 用于演示缓动效果 aniEasingDemo.EasingFunction = easingFunction; // 用于演示缓动轨迹 aniBallY.EasingFunction = easingFunction; // 画出当前缓动的曲线图 DrawEasingGraph(easingFunction); storyboard.Begin(); }
//Get Easing Function private EasingFunctionBase GetEasingFunction(Easing type) { EasingFunctionBase func = null; switch (type) { case Easing.EaseSineIn: case Easing.EaseSineOut: case Easing.EaseSineInOut: func = new SineEase(); break; case Easing.EaseCircleIn: case Easing.EaseCircleOut: case Easing.EaseCircleInOut: func = new CircleEase(); break; case Easing.EaseQuadraticIn: case Easing.EaseQuadraticOut: case Easing.EaseQuadraticInOut: func = new QuadraticEase(); break; case Easing.EaseCubicIn: case Easing.EaseCubicOut: case Easing.EaseCubicInOut: func = new CubicEase(); break; case Easing.EaseQuarticIn: case Easing.EaseQuarticOut: case Easing.EaseQuarticInOut: func = new QuarticEase(); break; case Easing.EaseQuinticIn: case Easing.EaseQuinticOut: case Easing.EaseQuinticInOut: func = new QuinticEase(); break; case Easing.EaseBackIn: case Easing.EaseBackOut: case Easing.EaseBackInOut: func = new BackEase(); break; case Easing.EaseBounceIn: case Easing.EaseBounceOut: case Easing.EaseBounceInOut: func = new BounceEase(); break; case Easing.EaseElasticIn: case Easing.EaseElasticOut: case Easing.EaseElasticInOut: func = new ElasticEase(); break; case Easing.EaseExpoIn: case Easing.EaseExpoOut: case Easing.EaseExpoInOut: func = new ExponentialEase(); break; case Easing.EasePowerIn: case Easing.EasePowerOut: case Easing.EasePowerInOut: func = new PowerEase(); break; default: break; } if (func != null) { switch ((int)type % 3) { case 0: func.EasingMode = EasingMode.EaseIn; break; case 1: func.EasingMode = EasingMode.EaseOut; break; default: func.EasingMode = EasingMode.EaseInOut; break; } } return(func); }