private void setupAnimation() { DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromSeconds(3))); da.AutoReverse = true; BounceEase bounce = new BounceEase(); bounce.Bounces = 4; bounce.Bounciness = 2; bounce.EasingMode = EasingMode.EaseOut; da.EasingFunction = bounce; TranslateTransform rt = new TranslateTransform(); faceGrid[0, 0].ParentGrid.RenderTransform = rt; faceGrid[0, 0].ParentGrid.RenderTransformOrigin = new Point(0.5, 0.5); for (int i = 0; i < IMAGE_MATRIX_WIDTH; i++) { for (int j = 0; j < IMAGE_MATRIX_HEIGHT; j++) { faceGrid[i, j].ParentGrid.RenderTransform = rt; faceGrid[i, j].ParentGrid.RenderTransformOrigin = new Point(0.5, 0.5); } } da.RepeatBehavior = RepeatBehavior.Forever; rt.BeginAnimation(TranslateTransform.XProperty, da); }
private void button4_Click(object sender, System.Windows.RoutedEventArgs e) { //定义多关键帧动画 DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames(); sb4 = new Storyboard(); this.sb4.Completed += new System.EventHandler(Storyboard_Completed); this.button1.IsEnabled = false; this.button2.IsEnabled = false; this.button3.IsEnabled = false; this.button4.IsEnabled = false; sb4.Children.Add(daukf); //动画影响属性:元素的三维旋转(以Y轴为旋转轴) Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")); Storyboard.SetTarget(daukf, image); //定义第1个可插入的关键帧(可以和Silverlight目前提供的11种缓动函数关联) //(缓动函数设置了关键帧之间的动画过渡状态) EasingDoubleKeyFrame kf1 = new EasingDoubleKeyFrame(); kf1.Value = 80; //设置此关键帧的目标值(旋转度数) kf1.KeyTime = new TimeSpan(0, 0, 0, 3); //设置达到目标值的时间(日,小时,分,秒) BackEase kf1be = new BackEase(); //定义具有收回效果的缓动函数对象 //EasingMode有3种选择:EaseIn、EaseOut和EaseInOut kf1be.EasingMode = EasingMode.EaseOut; //EaseOut方式 kf1.EasingFunction = kf1be; //第1帧使用缓动函数BackEase的EaseOut方式过渡 //定义第2个可插入的关键帧 EasingDoubleKeyFrame kf2 = new EasingDoubleKeyFrame(); kf2.Value = 0; kf2.KeyTime = new TimeSpan(0, 0, 0, 6); //第2帧达到第6秒 BounceEase kf2be = new BounceEase(); //定义具有反弹效果的缓动函数对象 kf2be.EasingMode = EasingMode.EaseIn; //EaseIn方式 kf2be.Bounces = 3; //反弹3次 kf2.EasingFunction = kf2be; //第2帧使用缓动函数BounceEase的EaseIn方式过渡 //定义第3个可插入的关键帧 EasingDoubleKeyFrame kf3 = new EasingDoubleKeyFrame(); kf3.Value = -80; kf3.KeyTime = new TimeSpan(0, 0, 0, 9); //第3帧达到第9秒 ElasticEase kf3ee = new ElasticEase(); //定义具有衰减振荡效果的缓动函数对象 kf3ee.EasingMode = EasingMode.EaseInOut; //EaseInOut方式 kf3ee.Oscillations = 4; //振荡次数 kf3ee.Ease(4); //衰减振荡持续时间 kf3.EasingFunction = kf3ee; //第3帧使用缓动函数ElasticEase的EaseInOut方式过渡 //定义第4个可插入的关键帧 EasingDoubleKeyFrame kf4 = new EasingDoubleKeyFrame(); kf4.Value = 0; kf4.KeyTime = new TimeSpan(0, 0, 0, 12); //第4帧达到第12秒 daukf.KeyFrames.Add(kf1); //添加关键帧 daukf.KeyFrames.Add(kf2); daukf.KeyFrames.Add(kf3); daukf.KeyFrames.Add(kf4); daukf.AutoReverse = true; //允许翻转 daukf.RepeatBehavior = new RepeatBehavior(1); //反复1次 sb4.Begin(); }
private void Button_Click(object sender, RoutedEventArgs e) { DoubleAnimation daX = new DoubleAnimation(); DoubleAnimation daY = new DoubleAnimation(); //设置 BounceEase be = new BounceEase(); be.Bounces = 3; //弹跳三次 be.Bounciness = 3; //弹跳程度,值越大反弹越低 daY.EasingFunction = be; //指定终点 Random r = new Random(); daX.To = 300; daY.To = 300; //指定时长 Duration duration = new Duration(TimeSpan.FromMilliseconds(2000)); daX.Duration = duration; daY.Duration = duration; //动画的主体是TranslateTransform变形,而非Button this.tt.BeginAnimation(TranslateTransform.XProperty, daX); this.tt.BeginAnimation(TranslateTransform.YProperty, daY); }
public NinjaCard(ScanInData inData) { // save ref to scan in ScanInData = inData; ScanInData.PropertyChanged += ScanInTick; // create shake animation _shakeAnim = new Storyboard(); var doubleAnimation = new DoubleAnimation { From = -10.0, To = 10.0, Duration = new Duration(TimeSpan.FromSeconds(1)), AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; doubleAnimation.SetValue(Storyboard.TargetNameProperty, nameof(MainGridTransform)); doubleAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath(TranslateTransform.XProperty)); var bounceEase = new BounceEase { Bounces = 1, Bounciness = 2.0, EasingMode = EasingMode.EaseOut }; doubleAnimation.EasingFunction = bounceEase; _shakeAnim.Children.Add(doubleAnimation); // set data context InitializeComponent(); MainGrid.DataContext = this; }
private void SetupSetScoreAnimation(bool show) { DoubleAnimation animateOpacity = _sbGetPlayerScore.Children[0] as DoubleAnimation; DoubleAnimation animateRotation = _sbGetPlayerScore.Children[1] as DoubleAnimation; animateOpacity.Duration = TimeSpan.FromMilliseconds(1000); animateRotation.Duration = TimeSpan.FromMilliseconds(1000); BounceEase bounce = ((DoubleAnimation)_sbGetPlayerScore.Children[1]).EasingFunction as BounceEase; if (show) { ((CompositeTransform)_gridGetScore.RenderTransform).Rotation = 90; animateOpacity.To = 1; animateRotation.To = 0; animateOpacity.BeginTime = TimeSpan.FromMilliseconds(0); animateRotation.BeginTime = TimeSpan.FromMilliseconds(500); bounce.Bounces = 1; } else { animateOpacity.To = 0; animateRotation.To = -270; animateRotation.BeginTime = TimeSpan.FromMilliseconds(0); animateOpacity.BeginTime = TimeSpan.FromMilliseconds(0); bounce.Bounces = 0; } }
private void btn_move_Click(object sender, RoutedEventArgs e) { DoubleAnimation daX = new DoubleAnimation(); DoubleAnimation daY = new DoubleAnimation(); //设置反弹 BounceEase be = new BounceEase(); be.Bounces = 3; //弹跳三次 be.Bounciness = 3; //弹性程度,值越大反弹越低 daY.EasingFunction = be; //指定终点 daX.To = 300; daY.To = 300; //指定时长 Duration dur = new Duration(TimeSpan.FromMilliseconds(300)); daX.Duration = dur; daY.Duration = dur; //启动动画 tt_demo.BeginAnimation(TranslateTransform.XProperty, daX); tt_demo.BeginAnimation(TranslateTransform.YProperty, daY); }
private void AnimationPos() { BitmapImage bt = new BitmapImage(new Uri(@"C:\Dados\TABERN\Propostas\HEMERA\Source\wpfOswSCR\wpfOswSCR\Images\Verax.png")); m_veraxImage.Source = bt; // im.Margin = new Thickness(-50, 500, 100, 100); mainPanel.Children.Add(m_veraxImage); m_veraxImage.SetValue(Canvas.LeftProperty, 1980.0); m_veraxImage.SetValue(Canvas.TopProperty, 100.0); //create an animation DoubleAnimation da = new DoubleAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; da.EasingFunction = BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error da.From = mainPanel.Width; //set second position of grid da.To = -1700; //set duration da.Duration = new Duration(TimeSpan.FromSeconds(8)); da.AutoReverse = true; //run animation if u want stop ,start etc use story board //*** m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); da.Completed += Da_Completed; m_actionVerax = new Action(delegate() { m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); }); }
private void AnimationPos() { Ellipse ellipse = new Ellipse(); ellipse.Fill = Brushes.Red; ellipse.Width = 10; ellipse.Height = 10; ellipse.SetValue(Canvas.LeftProperty, 100.0); ellipse.SetValue(Canvas.TopProperty, 100.0); canvas1.Children.Add(ellipse); //create an animation DoubleAnimation da = new DoubleAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; da.EasingFunction = BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error da.From = canvas1.Margin.Left; //set second position of grid da.To = -100; //set duration da.Duration = new Duration(TimeSpan.FromSeconds(2)); //run animation if u want stop ,start etc use story board ellipse.BeginAnimation(Canvas.LeftProperty, da); }
/* * public static void Animation_Translate_Frame(this UIElement E, double toX, double toY, double minisecond = 500, bool AutoReverse=false) * { * BounceEase BounceOrientation = new BounceEase(); * BounceOrientation.Bounces = 1; * BounceOrientation.Bounciness = 1; * // BounceOrientation.EasingMode = EasingMode.EaseInOut; * if (!double.IsNaN(toX)) * { * double fromX = E.getLeft(); * DoubleAnimation da = new DoubleAnimation(fromX, toX+fromX, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; * da.AutoReverse = AutoReverse; * E.BeginAnimation(Canvas.LeftProperty, da); * } * if (!double.IsNaN(toY)) * { * double fromY = E.getTop(); * DoubleAnimation db = new DoubleAnimation(fromY, fromY + toY, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; * db.AutoReverse = AutoReverse; * E.BeginAnimation(Canvas.TopProperty, db); * } * } * */ public static void Animation_Goto(this UIElement E, double toX, double toY, double minisecond = 500, bool AutoReverse = false) { BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 1; BounceOrientation.Bounciness = 1; // BounceOrientation.EasingMode = EasingMode.EaseInOut; if (!double.IsNaN(toX)) { double fromX = E.getLeft(); DoubleAnimation da = new DoubleAnimation(fromX, toX + fromX, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; da.AutoReverse = AutoReverse; E.BeginAnimation(Canvas.LeftProperty, da); } if (!double.IsNaN(toY)) { double fromY = E.getTop(); DoubleAnimation db = new DoubleAnimation(fromY, fromY + toY, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; db.AutoReverse = AutoReverse; E.BeginAnimation(Canvas.TopProperty, db); } }
/// <summary> /// The start animation. /// </summary> /// <param name="target"> /// The target. /// </param> /// <returns> /// The <see cref="Storyboard"/>. /// </returns> public override Storyboard GenerateAnimation(FrameworkElement target) { var ease = new BounceEase { Bounces = 3, EasingMode = EasingMode.EaseInOut, Bounciness = 2.0 }; var doubleAnimation = new DoubleAnimation { From = 0, To = 800, Duration = TimeSpan.FromSeconds(5), EasingFunction = ease }; Storyboard.SetTarget(doubleAnimation, target); Storyboard.SetTargetProperty( doubleAnimation, "(FrameworkElement.RenderTransform).(TranslateTransform.X)"); var storyboard = new Storyboard(); storyboard.Children.Add(doubleAnimation); return(storyboard); }
private void Button_Click3(object sender, RoutedEventArgs e) { DoubleAnimation daX = new DoubleAnimation(); DoubleAnimation daY = new DoubleAnimation(); //设置反弹 BounceEase be = new BounceEase(); be.Bounces = 3; be.Bounciness = 2; daY.EasingFunction = be; //指定终点 daX.To = 1000; daY.To = 600; //指定时长 Duration duration = new Duration(TimeSpan.FromMilliseconds(2000)); daX.Duration = daY.Duration = duration; //动画的主题是translateTransform变形,而非Button this.tt3.BeginAnimation(TranslateTransform.XProperty, daX); this.tt3.BeginAnimation(TranslateTransform.YProperty, daY); }
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); }
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); }
/// <summary> /// Obtiene una función Bounce /// </summary> private BounceEase GetBounceEase(BounceEaseModel bounceEase) { BounceEase ease = new BounceEase(); // Asigna las propiedades ease.Bounces = bounceEase.Bounces; ease.Bounciness = bounceEase.Bounciness; ease.EasingMode = ConvertEaseMode(bounceEase.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); }
public void When_FinalValueLowerThanInitial() { var sut = new BounceEase(); EaseCore(0.0).Should().BeApproximately(200, .1); EaseCore(1.0).Should().BeApproximately(100, .1); double EaseCore(double normalizedTime) => sut.Ease( currentTime: normalizedTime, duration: 1.0, startValue: 200, finalValue: 100); }
private void rectangle1_MouseDown(object sender, MouseButtonEventArgs e) { ThicknessAnimation bounceAnimation = new ThicknessAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; bounceAnimation.To = new Thickness(143, 200, 0, 0); bounceAnimation.From = new Thickness(143, 0, 0, 0); bounceAnimation.EasingFunction = BounceOrientation; rectangle1.BeginAnimation(MarginProperty, bounceAnimation); }
public static void ShakeAnimation(UserControl me) { ThicknessAnimation bounceAnimation = new ThicknessAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 2; BounceOrientation.Bounciness = .3; bounceAnimation.To = new Thickness(0, 0, 0, 0); bounceAnimation.From = new Thickness(15, 0, 0, 0); bounceAnimation.EasingFunction = BounceOrientation; me.BeginAnimation(FrameworkElement.MarginProperty, bounceAnimation); }
private void AnimacaoTranslate() { Storyboard stb = new Storyboard(); DoubleAnimation daX = new DoubleAnimation(); var exe = new BounceEase(); exe.EasingMode = EasingMode.EaseOut; daX.EasingFunction = exe; daX.From = -1000; daX.To = 0; daX.Duration = new Duration(new TimeSpan(0, 0, 0, 3, 0)); daX.BeginTime = new TimeSpan(0); Storyboard.SetTarget(daX, cptFundo); Storyboard.SetTargetProperty(daX, "RotateTransform.TranslateY"); stb.Children.Add(daX); stb.Begin(); }
private void AnimateTextBlock(string TextBlockContent) { TextBlockAnimationStory = new Storyboard(); DoubleAnimation animation = new DoubleAnimation(); Storyboard.SetTargetProperty(animation, new PropertyPath("RenderTransform.ScaleX")); Storyboard.SetTarget(animation, ResultTextBlock); animation.Duration = TimeSpan.FromSeconds(1); animation.From = 10; animation.To = 1; BounceEase easingFunction = new BounceEase(); easingFunction.Bounces = 3; easingFunction.EasingMode = EasingMode.EaseOut; easingFunction.Bounciness = 2; animation.EasingFunction = easingFunction; TextBlockAnimationStory.Children.Add(animation); ResultTextBlock.Text = TextBlockContent; TextBlockAnimationStory.Begin(); }
//EnableTextBoxMode private void jumpAnimation(Image target, double newY, double duration) { Vector offset = VisualTreeHelper.GetOffset(target); var top = offset.X; TranslateTransform translateTransform = new TranslateTransform(); target.RenderTransform = translateTransform; DoubleAnimation animate = new DoubleAnimation(0, newY - top, TimeSpan.FromSeconds(duration)); BounceEase bounce = new BounceEase(); bounce.EasingMode = EasingMode.EaseOut; animate.EasingFunction = bounce; animate.AutoReverse = true; animate.RepeatBehavior = RepeatBehavior.Forever; translateTransform.BeginAnimation(TranslateTransform.YProperty, animate); }
private void PrepareAnimation(FrameworkElement target, Point tp, FrameworkElement associatedObject, Point ap) { if (storyboard != null) { storyboard.Stop(); storyboard = null; } DoubleAnimation doubleanimationX = new DoubleAnimation(); doubleanimationX.Duration = TimeSpan.FromSeconds(1.4); doubleanimationX.To = tp.X + target.ActualWidth / 2 - _animationObject.ActualWidth / 2; doubleanimationX.From = ap.X + AssociatedObject.ActualWidth / 2 - _animationObject.ActualWidth / 2; doubleanimationX.AutoReverse = false; BounceEase ease = new BounceEase(); ease.Bounces = 1; ease.Bounciness = 40; ease.EasingMode = EasingMode.EaseOut; doubleanimationX.EasingFunction = ease; Storyboard.SetTarget(doubleanimationX, _animationObject); Storyboard.SetTargetProperty(doubleanimationX, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)"); DoubleAnimation doubleanimationY = new DoubleAnimation(); doubleanimationY.Duration = TimeSpan.FromSeconds(1.4); doubleanimationY.To = tp.Y + target.ActualHeight / 2 - _animationObject.ActualHeight / 2; doubleanimationY.From = ap.Y + AssociatedObject.ActualHeight / 2 - _animationObject.ActualHeight / 2; doubleanimationY.AutoReverse = false; Storyboard.SetTarget(doubleanimationY, _animationObject); Storyboard.SetTargetProperty(doubleanimationY, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)"); storyboard = new Storyboard(); storyboard.Children.Add(doubleanimationX); storyboard.Children.Add(doubleanimationY); storyboard.Completed += Storyboard_Completed; storyboard.Begin(); _animationObject.Visibility = Visibility.Visible; }
public void VisualBootup() { b_hintergrund.RenderTransform = new ScaleTransform(); Storyboard start = new Storyboard(); DoubleAnimationUsingKeyFrames Anim = new DoubleAnimationUsingKeyFrames(); BounceEase f = new BounceEase(); f.Bounciness = 5; Anim.KeyFrames.Add(new EasingDoubleKeyFrame(0.1, TimeSpan.FromSeconds(0), f)); Anim.KeyFrames.Add(new EasingDoubleKeyFrame(0.1, TimeSpan.FromSeconds(.2), f)); Anim.KeyFrames.Add(new EasingDoubleKeyFrame(1, TimeSpan.FromSeconds(.5), f)); Storyboard.SetTarget(Anim, b_hintergrund); Storyboard.SetTargetProperty(Anim, new PropertyPath("RenderTransform.ScaleY")); start.Children.Add(Anim); var da = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(.3)); Storyboard.SetTarget(da, b_hintergrund); Storyboard.SetTargetProperty(da, new PropertyPath("RenderTransform.ScaleX")); start.Children.Add(da); start.Completed += start_Completed; this.Visibility = Visibility.Visible; start.Begin(); }
private void Button_Click(object sender, RoutedEventArgs e) { DoubleAnimation daX = new DoubleAnimation(); DoubleAnimation daY = new DoubleAnimation(); //指定起点 //daX.From = 0d; //daY.From = 0d; //指定终点 Random r = new Random(); daX.To = r.NextDouble() * 300; daY.To = r.NextDouble() * 300; daX.AccelerationRatio = 0.8; daY.DecelerationRatio = 0.8; daX.SpeedRatio = 0.5; daX.AutoReverse = true; //设置反弹 BounceEase be = new BounceEase(); be.Bounces = 3; be.Bounciness = 1; daX.EasingFunction = be; //指定时长 Duration duration = new Duration(TimeSpan.FromMilliseconds(300)); daX.Duration = duration; daY.Duration = duration; //动画的主体是TranslateTransform变形而非Button this.tt.BeginAnimation(TranslateTransform.XProperty, daX); tt.BeginAnimation(TranslateTransform.YProperty, daY); }
private void SwapShowStoryBegin(FrameworkElement sourceUI, FrameworkElement targetUI) { BounceEase bounceease = new BounceEase(); bounceease.Bounces = 1; bounceease.Bounciness = 10; bounceease.EasingMode = EasingMode.EaseOut; bounceease.Freeze(); Storyboard shows = new Storyboard(); DoubleAnimation scalex1 = new DoubleAnimation() { From = 0, To = 1, Duration = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(scalex1, sourceUI); Storyboard.SetTargetProperty(scalex1, new PropertyPath("(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)")); scalex1.EasingFunction = bounceease; DoubleAnimation scalex2 = new DoubleAnimation() { From = 0, To = 1, Duration = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(scalex2, targetUI); Storyboard.SetTargetProperty(scalex2, new PropertyPath("(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)")); scalex2.EasingFunction = bounceease; shows.Children.Add(scalex1); shows.Children.Add(scalex2); shows.Completed += shows_Completed; shows.Begin(); }
private void AnimationText() { m_txb = new Label(); m_txb.Content = "Boas Festas!!! - Verax"; m_txb.FontSize = 120; m_txb.FontFamily = new FontFamily("Bauhaus 93"); object oo = FontFamily.FamilyNames.Values; SolidColorBrush textBrush = new SolidColorBrush(Colors.Blue); m_txb.Foreground = textBrush; DropShadowEffect eff = new DropShadowEffect(); eff.BlurRadius = 25; // Color="LightGreen" ShadowDepth="0" Direction="0" BlurRadius="25" eff.Color = Colors.Yellow; eff.ShadowDepth = 0; eff.Direction = 0; m_txb.Effect = eff; m_txb.SetValue(Canvas.LeftProperty, 10.0); m_txb.SetValue(Canvas.TopProperty, 10.0); mainPanel.Children.Add(m_txb); //create an animation DoubleAnimation da = new DoubleAnimation(); DoubleAnimation db = new DoubleAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; ElasticEase elastic = new ElasticEase(); elastic.Oscillations = 2; elastic.Springiness = 2; Storyboard sb = new Storyboard(); CircleEase circle = new CircleEase(); circle.Ease(13); //** db.EasingFunction = elastic; //elastic; // BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error db.From = mainPanel.Width; //set second position of grid db.To = -1300; //set duration db.Duration = new Duration(TimeSpan.FromSeconds(18)); db.AutoReverse = true; db.RepeatBehavior = RepeatBehavior.Forever; db.EasingFunction = circle; // BounceOrientation; da.From = 0.0; da.To = mainPanel.Height - 500; da.Duration = new Duration(TimeSpan.FromSeconds(18)); da.RepeatBehavior = RepeatBehavior.Forever; da.EasingFunction = elastic; //run animation if u want stop ,start etc use story board //*** m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); sb.Children.Add(da); sb.Children.Add(db); // Register the brush's name this.RegisterName("Brush1", textBrush); LinearGradientBrushAnimation la = new LinearGradientBrushAnimation(); var resources = App.Current.Resources.MergedDictionaries; // window1.Resources.MergedDictionaries; object o2 = (resources[1] as ResourceDictionary); //.Values.GetEnumerator().Current; // as LinearGradientBrush)); object[] keys = (o2 as ResourceDictionary).Keys as object[]; la.From = (o2 as ResourceDictionary)[keys[0]] as LinearGradientBrush; la.To = (o2 as ResourceDictionary)[keys[1]] as LinearGradientBrush; la.RepeatBehavior = RepeatBehavior.Forever; la.AutoReverse = true; la.Duration = TimeSpan.FromSeconds(1); m_txb.Foreground = (o2 as ResourceDictionary)[keys[0]] as LinearGradientBrush; m_txb.BeginAnimation(Label.ForegroundProperty, la); Storyboard.SetTarget(da, m_txb); Storyboard.SetTarget(db, m_txb); Storyboard.SetTargetProperty(db, new PropertyPath(Canvas.LeftProperty)); Storyboard.SetTargetProperty(da, new PropertyPath(Canvas.TopProperty)); //m_veraxTxb = new Action(delegate () { // m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); // falaSerial.write(m_coresTexto[contaCor % m_cores.Length]); // System.Diagnostics.Debug.WriteLine("m_veraxTxb.BeginAnimation(Canvas.LeftProperty, da..."); //}); System.Diagnostics.Debug.WriteLine("m_veraxTxb.BeginAnimation(Canvas.LeftProperty, db..."); //m_txb.BeginAnimation(SolidColorBrush.ColorProperty, cc); sb.Begin(); //m_txb.BeginAnimation(TextBlock.ForegroundProperty ,cc); }
private void AnimationPos() { TextBlock txb = new TextBlock(); txb.Text = "Boas Festas!!! - Verax"; txb.FontSize = 80; txb.Foreground = Brushes.Lime; DropShadowEffect eff = new DropShadowEffect(); eff.BlurRadius = 25; // Color="LightGreen" ShadowDepth="0" Direction="0" BlurRadius="25" eff.Color = Colors.Yellow; eff.ShadowDepth = 0; eff.Direction = 0; txb.Effect = eff; txb.SetValue(Canvas.LeftProperty, 10.0); txb.SetValue(Canvas.TopProperty, 10.0); //mainPanel.Children.Add(txb); BitmapImage bt = new BitmapImage(new Uri(@"C:\Dados\TABERN\Propostas\HEMERA\Source\wpfOswSCR\wpfOswSCR\Images\Verax.png")); m_veraxImage.Source = bt; // im.Margin = new Thickness(-50, 500, 100, 100); mainPanel.Children.Add(m_veraxImage); m_veraxImage.SetValue(Canvas.LeftProperty, 1980.0); m_veraxImage.SetValue(Canvas.TopProperty, 100.0); //create an animation DoubleAnimation da = new DoubleAnimation(); DoubleAnimation db = new DoubleAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; ElasticEase elastic = new ElasticEase(); elastic.Oscillations = 2; elastic.Springiness = 2; CircleEase circle = new CircleEase(); circle.Ease(3); da.EasingFunction = circle; //elastic; // BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error da.From = mainPanel.Width; //set second position of grid da.To = 00; //set duration da.Duration = new Duration(TimeSpan.FromSeconds(3)); da.AutoReverse = true; //run animation if u want stop ,start etc use story board //*** m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); da.Completed += Da_Completed; db.EasingFunction = circle; //elastic; // BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error db.From = mainPanel.Width; //set second position of grid db.To = 00; //set duration db.Duration = new Duration(TimeSpan.FromSeconds(3)); db.AutoReverse = true; //run animation if u want stop ,start etc use story board //*** m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); m_actionVerax = new Action(delegate() { m_veraxImage.BeginAnimation(Canvas.LeftProperty, da); falaSerial.write(m_coresTexto[contaCor % m_cores.Length]); System.Diagnostics.Debug.WriteLine("m_veraxImage.BeginAnimation(Canvas.LeftProperty, da..."); }); // txb.BeginAnimation(Canvas.LeftProperty, db); }
private void AnimationText() { Canvas mainPanel = canvas1; mainPanel.Background = Brushes.Black; m_txb = new TextBlock(); m_txb.Text = "Boas Festas!!! - Verax---"; m_txb.FontSize = 80; m_txb.Foreground = Brushes.Lime; DropShadowEffect eff = new DropShadowEffect(); eff.BlurRadius = 25; // Color="LightGreen" ShadowDepth="0" Direction="0" BlurRadius="25" eff.Color = Colors.Yellow; eff.ShadowDepth = 0; eff.Direction = 0; m_txb.Effect = eff; m_txb.SetValue(Canvas.LeftProperty, 10.0); m_txb.SetValue(Canvas.TopProperty, 10.0); mainPanel.Children.Add(m_txb); // m_txb.SetValue(Canvas.LeftProperty, 180.0); // m_txb.SetValue(Canvas.TopProperty, 1800.0); //create an animation DoubleAnimation db = new DoubleAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; ElasticEase elastic = new ElasticEase(); elastic.Oscillations = 2; elastic.Springiness = 2; CircleEase circle = new CircleEase(); circle.Ease(3); //db.EasingFunction = circle; //elastic; // BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error db.From = 400; //set second position of grid db.To = 00; //set duration db.Duration = new Duration(TimeSpan.FromSeconds(3)); db.AutoReverse = true; db.EasingFunction = BounceOrientation; DoubleAnimation dc = db.Clone(); dc.EasingFunction = elastic; Storyboard sb = new Storyboard(); sb.Children.Add(db); sb.Children.Add(dc); Storyboard.SetTarget(db, m_txb); Storyboard.SetTarget(dc, m_txb); Storyboard.SetTargetProperty(db, new PropertyPath(Canvas.TopProperty)); Storyboard.SetTargetProperty(dc, new PropertyPath(Canvas.LeftProperty)); //Storyboard.SetTargetProperty(db, Canvas.LeftProperty); GradientStopCollection gcolFrom = new GradientStopCollection(); gcolFrom.Add(new GradientStop(Colors.Black, 10)); GradientStopCollection gcolTo = new GradientStopCollection(); gcolFrom.Add(new GradientStop(Colors.Red, 10)); LinearGradientBrushAnimation linan = new LinearGradientBrushAnimation(); linan.From = new LinearGradientBrush(gcolFrom, 90); linan.To = new LinearGradientBrush(gcolTo, 90); this.RegisterName("linan", linan); sb.Children.Add(linan); Storyboard.SetTargetName(linan, "linan"); Storyboard.SetTargetProperty(linan, new PropertyPath(TextBlock.ForegroundProperty)); System.Diagnostics.Debug.WriteLine("m_veraxTxb.BeginAnimation(Canvas.LeftProperty, db..."); //m_txb.BeginAnimation(Canvas.LeftProperty, db); canvas1.Resources.Add("unique_id", sb); sb.Begin(); }
private void Timer_Tick(object sender, EventArgs e) { if (!flag_control) { return; } //mainCanvas.Children.Clear(); offsetAngleList.Clear(); int max_deep = 5;//максимальная глубина рекурсии(количество слоев) //зададим размеры холста для формирования фигуры, иначе будет обрезана double size = 1000; //сгенерируем фигуру GenerateFractalSnowFirst(rand.Next(50, 150), TypeFractalPrimitive.Line, new Point(size / 2, size / 2), rand.Next(360), rand.Next(3, max_deep)); //используя полученную сокращенную запись фигуры, создадим ее Path new_path = CreateFigureFromPath(currentPath); //окрасим фигуру new_path.Stroke = new LinearGradientBrush(Color.FromArgb((byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255)), Color.FromArgb((byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255)), 0.0); new_path.RenderTransformOrigin = new Point(0.5, 0.5); var storyboard = new Storyboard(); //************************************************** //************************************************** //************************************************** //Заменим стиль на code-behind для общего контролля всеми эффектами // new_path.Style = (Style)TryFindResource("PathShadow");//наложим эффекты и любые другие стили new_path.Effect = new DropShadowEffect() { Color = Colors.Red, Direction = 100, RenderingBias = RenderingBias.Quality, ShadowDepth = 0, BlurRadius = 10, Opacity = 1 }; DoubleAnimation shadowDepth = new DoubleAnimation(); shadowDepth.From = 0; shadowDepth.To = 7; shadowDepth.Duration = TimeSpan.FromSeconds(1.5); shadowDepth.AutoReverse = true; shadowDepth.RepeatBehavior = RepeatBehavior.Forever; storyboard.Children.Add(shadowDepth); Storyboard.SetTarget(shadowDepth, new_path); Storyboard.SetTargetProperty(shadowDepth, new PropertyPath("Effect.ShadowDepth")); DoubleAnimation direction = new DoubleAnimation(); direction.From = 100; direction.To = 460; direction.Duration = TimeSpan.FromSeconds(4); direction.RepeatBehavior = RepeatBehavior.Forever; storyboard.Children.Add(direction); Storyboard.SetTarget(direction, new_path); Storyboard.SetTargetProperty(direction, new PropertyPath("Effect.Direction")); ColorAnimation color = new ColorAnimation(); color.To = Colors.Blue; color.Duration = TimeSpan.FromSeconds(8); color.AutoReverse = true; color.RepeatBehavior = RepeatBehavior.Forever; storyboard.Children.Add(color); Storyboard.SetTarget(color, new_path); Storyboard.SetTargetProperty(color, new PropertyPath("Effect.Color")); //************************************************** //************************************************** //************************************************** new_path.Width = size; new_path.Height = size; // Path new_canvas = new_path; //разместим фигуру на холсте, его и будем анимировать Canvas new_canvas = new Canvas() { RenderTransformOrigin = new Point(0.5, 0.5), Width = size, Height = size }; new_canvas.Children.Add(new_path); //отцентрируем нашу фигуру, совместим центр фигуры с верхним левым углом Canvas //ведь его мы будем анимировать - двигать по X и Y Canvas.SetTop(new_path, -size / 2); Canvas.SetLeft(new_path, -size / 2); //установим время всех анимаций double timeAnimation = 2 + rand.NextDouble() * 10; //Движение сверху-вниз(падение) с эффектом отскока BounceEase ease = new BounceEase(); ease.EasingMode = EasingMode.EaseOut; ease.Bounces = rand.Next(2, 10); DoubleAnimation downAnimation = new DoubleAnimation(); downAnimation.From = 0; downAnimation.To = mainCanvas.ActualHeight; downAnimation.EasingFunction = ease; downAnimation.Duration = TimeSpan.FromSeconds(timeAnimation); // new_canvas.BeginAnimation(Canvas.TopProperty, downAnimation); storyboard.Children.Add(downAnimation); Storyboard.SetTarget(downAnimation, new_canvas); Storyboard.SetTargetProperty(downAnimation, new PropertyPath("Top")); //Движение слева-направо, колебания, смещение, флуктуации SinusEase easySinus = new SinusEase(); easySinus.EasingMode = EasingMode.EaseIn; easySinus.Amplitude = 0.1; easySinus.Period = rand.Next(1, 5); DoubleAnimation leftAnimation = new DoubleAnimation(); leftAnimation.From = rand.Next((int)mainCanvas.ActualWidth); leftAnimation.To = rand.Next((int)mainCanvas.ActualWidth); leftAnimation.EasingFunction = easySinus; leftAnimation.Duration = TimeSpan.FromSeconds(timeAnimation); // new_canvas.BeginAnimation(Canvas.LeftProperty, leftAnimation); storyboard.Children.Add(leftAnimation); Storyboard.SetTarget(leftAnimation, new_canvas); Storyboard.SetTargetProperty(leftAnimation, new PropertyPath("Left")); //наложим общие эффекты преобразования var tg = new TransformGroup(); //масштабирование var scale = new ScaleTransform() { ScaleX = 1, ScaleY = 1, CenterX = new_path.Width / 2, CenterY = new_path.Height / 2 }; tg.Children.Add(scale); //вращение var rotate = new RotateTransform() { Angle = 0 }; tg.Children.Add(rotate); new_canvas.RenderTransform = tg; //МАСШТАБИРОВАНИЕ НЕ ПОЛУЧИЛОСЬ // DoubleAnimation scaleXAnimation = new DoubleAnimation(); // scaleXAnimation.From =0.1 + rand.NextDouble(); // scaleXAnimation.To = 0.5*rand.NextDouble(); // scaleXAnimation.AutoReverse = true; // //scaleXYAnimation.RepeatBehavior = RepeatBehavior.Forever; // scaleXAnimation.Duration = TimeSpan.FromSeconds(timeAnimation); // // DoubleAnimation scaleYAnimation = new DoubleAnimation(); // scaleYAnimation.From = 0.1 + rand.NextDouble(); // scaleYAnimation.To = 0.5 * rand.NextDouble(); // scaleYAnimation.AutoReverse = true; // scaleYAnimation.By = rand.Next(1, 5); // //scaleXYAnimation.RepeatBehavior = RepeatBehavior.Forever; // scaleYAnimation.Duration = TimeSpan.FromSeconds(timeAnimation); //вращение DoubleAnimation rotateAnimation = new DoubleAnimation(); rotateAnimation.From = 0; rotateAnimation.To = 360 * rand.Next(1, 3); //rotateAnimation.RepeatBehavior = RepeatBehavior.Forever; rotateAnimation.Duration = TimeSpan.FromSeconds(timeAnimation); //обесцвечивание - исчезание, перед удалением DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.From = 1; opacityAnimation.To = 0; opacityAnimation.Duration = TimeSpan.FromSeconds(timeAnimation + 15); //через 15 секунд удалим обьект opacityAnimation.BeginTime = TimeSpan.FromSeconds(timeAnimation); //начнем когда анимации завершены mainCanvas.Children.Add(new_canvas); //Canvas.SetTop(new_canvas, -size / 2); // var storyboard = new Storyboard(); // storyboard.Children.Add(scaleXAnimation); // storyboard.Children.Add(scaleYAnimation); storyboard.Children.Add(rotateAnimation); storyboard.Children.Add(opacityAnimation); //Storyboard.SetTarget(scaleXAnimation, new_path); //Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("RenderTransform.Children[0].ScaleX")); //Storyboard.SetTarget(scaleXAnimation, new_path); //Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("RenderTransform.Children[0].ScaleY")); Storyboard.SetTarget(rotateAnimation, new_path); Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath("RenderTransform.Children[1].Angle")); Storyboard.SetTarget(opacityAnimation, new_path); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity")); //storyboard.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation); storyboard.Completed += (sndr, evtArgs) => { mainCanvas.Children.Remove(new_canvas); //по завершению анимирования данного обьекта, удалить storyboardList.Remove(storyboard); }; //отображение пути if (flag_show_way) { // storyboard.CurrentTimeInvalidated += Storyboard_CurrentTimeInvalidated; storyboard.CurrentTimeInvalidated += (sndr, evtArgs) => { if (flag_show_way) //рисуем только если установлен флаг { double x = Canvas.GetLeft(new_canvas); // + new_canvas.RenderSize.Width / 2; double y = Canvas.GetTop(new_canvas); // + new_canvas.RenderSize.Height / 2; //Console.WriteLine(@"x = {0}, y = {1}", x, y); Ellipse point = new Ellipse(); point.StrokeThickness = 0; point.Fill = new SolidColorBrush(Colors.Red); point.Width = 3; point.Height = 3; Canvas.SetLeft(point, x); Canvas.SetTop(point, y); mainCanvas.Children.Add(point); removeList.Add(point);//учтем все нарисованные точки, для оперативного удаления } }; } else { //удаление пути с холста if (removeList.Count > 0) { //очистим поле от точек пути foreach (var item in removeList) { mainCanvas.Children.Remove(item); } removeList.Clear(); } } storyboard.Begin(); storyboardList.Add(storyboard); }
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); }