public void Flush()
        {
            var thicknessAnimationUsingKeyFrames = new ThicknessAnimationUsingKeyFrames();
            thicknessAnimationUsingKeyFrames.KeyFrames = new ThicknessKeyFrameCollection();

            double delta = (Width - Height) / 2;

            var thicknessAnimation = new ThicknessAnimation()
            {
                From = new Thickness(delta, 0, delta, 0),
                To = new Thickness(delta - 500, -500, delta - 500, -500),
                Duration = new Duration(TimeSpan.FromSeconds(1)),
                AutoReverse = true
            };
            thicknessAnimation.Completed += new EventHandler(animation_Completed);

            _flushEllipse = new Ellipse()
            {
                Fill = new SolidColorBrush(Colors.LightBlue),
                Stroke = new SolidColorBrush(Colors.Orange),
                StrokeThickness = 5,
                Opacity = 0.5
            };

            Children.Add(_flushEllipse);
            _flushEllipse.BeginAnimation(Ellipse.MarginProperty, thicknessAnimation);
        }
Beispiel #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Ellipse ellipse1 = new Ellipse();
            ellipse1.Width = 50;
            ellipse1.Height = 20;
            ellipse1.ToolTip = "Touch Me / Потискай меня";
            ellipse1.StrokeThickness = 2;
            ellipse1.Stroke = Brushes.Black;
            ellipse1.Fill = Brushes.Red;
            Mygrid.Children.Add(ellipse1);

            Ellipse ellipse2 = new Ellipse();
            ellipse2.Width = 50;
            ellipse2.Height = 20;
            ellipse2.ToolTip = "Touch Me / Потискай меня";
            ellipse2.StrokeThickness = 2;
            ellipse2.Stroke = Brushes.Red;
            ellipse2.Fill = Brushes.Green;
            Mygrid.Children.Add(ellipse2);

            Random rand1 = new Random((int)DateTime.Now.Ticks);
            Random rand2 = new Random((int)DateTime.Now.Ticks);
            ThicknessAnimation TA1 = new ThicknessAnimation(); //Анимация перемещения
            TA1.From = ellipse1.Margin = new Thickness(10, 100, 0, 0); //Координаты начального положения
            TA1.To = ellipse1.Margin = new Thickness(1400, 100, 0, 0); //Координаты конечного положения
            TA1.Duration = TimeSpan.FromSeconds(rand1.Next(10, 20)); //Время анимации
            ellipse1.BeginAnimation(MarginProperty, TA1); //Запуск анимации

            ThicknessAnimation TA2 = new ThicknessAnimation(); //Анимация перемещения
            TA2.From = ellipse2.Margin = new Thickness(10, 200, 0, 0); //Координаты начального положения
            TA2.To = ellipse2.Margin = new Thickness(1400, 200, 0, 0); //Координаты конечного положения
            TA2.Duration = TimeSpan.FromSeconds(rand2.Next(10, 20)); //Время анимации
            ellipse2.BeginAnimation(MarginProperty, TA2); //Запуск анимации
        }
Beispiel #3
0
        public void AnimateBall(ThrowResultDT result, int yPos)
        {
            resultThrow = result;
            DoubleAnimation anime = new DoubleAnimation();

            anime.From = Convert.ToDouble(ball.GetValue(Canvas.TopProperty));
            anime.To   = Convert.ToDouble(yPos);
            if (yPos > 360)
            {
                anime.Duration = TimeSpan.FromSeconds(0.1);
            }
            else if (yPos > 300)
            {
                anime.Duration = TimeSpan.FromSeconds(0.2);
            }
            else if (yPos > 240)
            {
                anime.Duration = TimeSpan.FromSeconds(0.3);
            }
            else if (yPos > 180)
            {
                anime.Duration = TimeSpan.FromSeconds(0.4);
            }
            else if (yPos > 120)
            {
                anime.Duration = TimeSpan.FromSeconds(0.5);
            }
            else
            {
                anime.Duration = TimeSpan.FromSeconds(0.6);
            }

            anime.Completed += new EventHandler(anime_Completed);
            //  anime.DecelerationRatio = 0.3;
            ball.BeginAnimation(Canvas.TopProperty, anime);
        }
Beispiel #4
0
        public override void Plot(bool animate = true)
        {
            if (Visibility != Visibility.Visible) return;
            var chart = Chart as RadarChart;
            if (chart == null) return;
            var alpha = 360 / chart.Max.X;

            var pf = new PathFigure();
            var segments = new PathSegmentCollection();
            var l = 0d;

            Point? p2 = null;

            if (!Values.Points.Any()) return;
            var lastPoint = Values.Points.Last();
            var fisrtPoint = Values.Points.First();
            foreach (var point in Values.Points)
            {
                var r1 = point != lastPoint
                    ? chart.ToChartRadius(point.Y)
                    : chart.ToChartRadius(fisrtPoint.Y);
                if (point == fisrtPoint)
                    pf.StartPoint = new Point(
                        chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                        chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1);
                else
                    segments.Add(new LineSegment
                    {
                        Point = new Point
                        {
                            X = chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                            Y = chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1
                        }
                    });

                var p1 = new Point(chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                    chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1);
                if (p2 != null)
                {
                    l += Math.Sqrt(
                        Math.Pow(Math.Abs(p1.X - p2.Value.X), 2) +
                        Math.Pow(Math.Abs(p1.Y - p2.Value.Y), 2)
                        );
                }
                p2 = p1;

                if (point == lastPoint) continue;

                var r = new Rectangle
                {
                    Fill = Brushes.Transparent,
                    Width = 40,
                    Height = 40
                };
                var e = new Ellipse
                {
                    Width = PointRadius*2,
                    Height = PointRadius*2,
                    Fill = Stroke,
                    Stroke = new SolidColorBrush {Color = Chart.PointHoverColor},
                    StrokeThickness = 2
                };

                r.MouseEnter += chart.DataMouseEnter;
                r.MouseLeave += chart.DataMouseLeave;
                r.MouseDown += chart.DataMouseDown;
                chart.Canvas.Children.Add(r);
                Shapes.Add(r);
                chart.HoverableShapes.Add(new HoverableShape
                {
                    Series = this,
                    Shape = r,
                    Value = point,
                    Target = e
                });

                Shapes.Add(e);
                chart.Canvas.Children.Add(e);
                Panel.SetZIndex(r, int.MaxValue);

                Canvas.SetLeft(e, p1.X - e.Width/2);
                Canvas.SetTop(e, p1.Y - e.Height/2);
                Panel.SetZIndex(e, 2);

                Canvas.SetLeft(r, p1.X - r.Width/2);
                Canvas.SetTop(r, p1.Y - r.Height/2);
                Panel.SetZIndex(r, int.MaxValue);

                if (!chart.DisableAnimation && animate)
                {
                    var topAnim = new DoubleAnimation
                    {
                        From = chart.ActualHeight/2,
                        To = p1.Y - e.Height/2,
                        Duration = TimeSpan.FromMilliseconds(300)
                    };
                    e.BeginAnimation(Canvas.TopProperty, topAnim);
                    var leftAnim = new DoubleAnimation
                    {
                        From = chart.ActualWidth/2,
                        To = p1.X - e.Width/2,
                        Duration = TimeSpan.FromMilliseconds(300)
                    };
                    e.BeginAnimation(Canvas.LeftProperty, leftAnim);
                }

            }

            pf.Segments = segments;
            var g = new PathGeometry
            {
                Figures = new PathFigureCollection(new List<PathFigure>
                {
                    pf
                })
            };

            var path = new Path
            {
                Stroke = Stroke,
                StrokeThickness = StrokeThickness,
                Data = g,
                StrokeEndLineCap = PenLineCap.Round,
                StrokeStartLineCap = PenLineCap.Round,
                Fill = Fill,
                StrokeDashOffset = l,
                StrokeDashArray = new DoubleCollection { l, l }
            };

            var draw = new DoubleAnimationUsingKeyFrames
            {
                BeginTime = TimeSpan.FromSeconds(0),
                KeyFrames = new DoubleKeyFrameCollection
                {
                    new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromMilliseconds(1),
                        Value = l
                    },
                    new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromMilliseconds(750),
                        Value = 0
                    }
                }
            };
            Storyboard.SetTarget(draw, path);
            Storyboard.SetTargetProperty(draw, new PropertyPath(Shape.StrokeDashOffsetProperty));
            var sbDraw = new Storyboard();
            sbDraw.Children.Add(draw);
            var animated = false;
            if (!chart.DisableAnimation)
            {
                if (animate)
                {
                    sbDraw.Begin();
                    animated = true;
                }
            }
            if (!animated) path.StrokeDashOffset = 0;

            chart.Canvas.Children.Add(path);
            Shapes.Add(path);
        }
 /// <summary>
 /// Animates a single vertex
 /// </summary>
 /// <param name="vertex">Vertex to be animated</param>
 /// <param name="opacityAnim">Animation to be used</param>
 private void AnimVertex(Ellipse vertex, DoubleAnimation opacityAnim)
 {
     vertex.BeginAnimation(Ellipse.OpacityProperty, opacityAnim);
 }
Beispiel #6
0
        private void CreateCircles()
        {
            double centerX = this.MainCanvas.ActualWidth / 2.0;
            double centerY = this.MainCanvas.ActualHeight / 2.0;

            Color[] colors = new Color[] { Colors.White, Colors.Green, Colors.Green, Colors.Lime };

            for (int i = 0; i < 24; ++i)
            {
                Ellipse e = new Ellipse();
                byte alpha = (byte)rand.Next(96, 192);
                int colorIndex = rand.Next(4);
                e.Stroke = new SolidColorBrush(Color.FromArgb(alpha, colors[colorIndex].R, colors[colorIndex].G, colors[colorIndex].B));
                e.StrokeThickness = rand.Next(1, 4);
                e.Width = 0.0;
                e.Height = 0.0;
                double offsetX = 16 - rand.Next(32);
                double offsetY = 16 - rand.Next(32);

                this.MainCanvas.Children.Add(e);

                e.SetValue(Canvas.LeftProperty, centerX + offsetX);
                e.SetValue(Canvas.TopProperty, centerY + offsetY);

                double duration = 6.0 + 10.0 * rand.NextDouble();
                double delay = 16.0 * rand.NextDouble();

                TranslateTransform offsetTransform = new TranslateTransform();

                DoubleAnimation offsetXAnimation = new DoubleAnimation(0.0, -256.0, new Duration(TimeSpan.FromSeconds(duration)));
                offsetXAnimation.RepeatBehavior = RepeatBehavior.Forever;
                offsetXAnimation.BeginTime = TimeSpan.FromSeconds(delay);
                offsetTransform.BeginAnimation(TranslateTransform.XProperty, offsetXAnimation);
                offsetTransform.BeginAnimation(TranslateTransform.YProperty, offsetXAnimation);

                e.RenderTransform = offsetTransform;

                DoubleAnimation sizeAnimation = new DoubleAnimation(0.0, 512.0, new Duration(TimeSpan.FromSeconds(duration)));
                sizeAnimation.RepeatBehavior = RepeatBehavior.Forever;
                sizeAnimation.BeginTime = TimeSpan.FromSeconds(delay);
                e.BeginAnimation(Ellipse.WidthProperty, sizeAnimation);
                e.BeginAnimation(Ellipse.HeightProperty, sizeAnimation);

                DoubleAnimation opacityAnimation = new DoubleAnimation(duration - 1.0, 0.0, new Duration(TimeSpan.FromSeconds(duration)));
                opacityAnimation.BeginTime = TimeSpan.FromSeconds(delay);
                opacityAnimation.RepeatBehavior = RepeatBehavior.Forever;
                e.BeginAnimation(Ellipse.OpacityProperty, opacityAnimation);

            }
        }
Beispiel #7
0
        private void CreateCircles()
        {
            var centerX = MainCanvas.ActualWidth/2.0;
            var centerY = MainCanvas.ActualHeight/2.0;

            Color[] colors = {Colors.White, Colors.Green, Colors.Green, Colors.Lime};

            for (var i = 0; i < 24; ++i)
            {
                var e = new Ellipse();
                var alpha = (byte) _rand.Next(96, 192);
                var colorIndex = _rand.Next(4);
                e.Stroke =
                    new SolidColorBrush(Color.FromArgb(alpha, colors[colorIndex].R, colors[colorIndex].G,
                        colors[colorIndex].B));
                e.StrokeThickness = _rand.Next(1, 4);
                e.Width = 0.0;
                e.Height = 0.0;
                double offsetX = 16 - _rand.Next(32);
                double offsetY = 16 - _rand.Next(32);

                MainCanvas.Children.Add(e);

                e.SetValue(Canvas.LeftProperty, centerX + offsetX);
                e.SetValue(Canvas.TopProperty, centerY + offsetY);

                var duration = 6.0 + 10.0*_rand.NextDouble();
                var delay = 16.0*_rand.NextDouble();

                var offsetTransform = new TranslateTransform();

                var offsetXAnimation = new DoubleAnimation(0.0, -256.0, new Duration(TimeSpan.FromSeconds(duration)))
                {
                    RepeatBehavior = RepeatBehavior.Forever,
                    BeginTime = TimeSpan.FromSeconds(delay)
                };
                offsetTransform.BeginAnimation(TranslateTransform.XProperty, offsetXAnimation);
                offsetTransform.BeginAnimation(TranslateTransform.YProperty, offsetXAnimation);

                e.RenderTransform = offsetTransform;


                var sizeAnimation = new DoubleAnimation(0.0, 512.0, new Duration(TimeSpan.FromSeconds(duration)))
                {
                    RepeatBehavior = RepeatBehavior.Forever,
                    BeginTime = TimeSpan.FromSeconds(delay)
                };
                e.BeginAnimation(WidthProperty, sizeAnimation);
                e.BeginAnimation(HeightProperty, sizeAnimation);

                var opacityAnimation = new DoubleAnimation(duration - 1.0, 0.0,
                    new Duration(TimeSpan.FromSeconds(duration)))
                {
                    BeginTime = TimeSpan.FromSeconds(delay),
                    RepeatBehavior = RepeatBehavior.Forever
                };
                e.BeginAnimation(OpacityProperty, opacityAnimation);
            }
        }