private void startBrickAnimation()
        {
            PointAnimationUsingPath ballAnimation = new PointAnimationUsingPath();
            PathGeometry            animationPath = new PathGeometry();
            PathFigure pFigure = new PathFigure();

            //I don't know how to get its position....
            pFigure.StartPoint = new Point(607, 228);
            Point endPoint = new Point(200, 200);

            pFigure.Segments.Add(MainView.ComputeCurve(pFigure.StartPoint, endPoint, new Vector(0, 0)));

            animationPath.Figures.Add(pFigure);
            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            /*
             * animationPath.Figures = pfc;*/
            ballAnimation.PathGeometry = animationPath;
            ballAnimation.BeginTime    = TimeSpan.FromSeconds(0);
            ballAnimation.Duration     = new Duration(TimeSpan.FromSeconds(2));
            ballAnimation.AutoReverse  = false;

            Storyboard.SetTarget(ballAnimation, bird2);
            Storyboard.SetTargetProperty(ballAnimation, new PropertyPath("(TopLeft)"));
            Storyboard ballMove = new Storyboard();

            ballMove.Children.Add(ballAnimation);

            ballMove.Completed += delegate
            {
                this.SendMessage(new ChangeViewMessage(typeof(MainView)));
            };
            ballMove.Begin();
        }
示例#2
0
        private void HitBall(int index, Vector velocity, bool isPlayerOne)
        {
            var heldBalls   = isPlayerOne ? game.PlayerOneHeldBalls : game.PlayerTwoHeldBalls;
            var ballHolders = isPlayerOne ? _playerOneBallHolders : _playerTwoBallHolders;
            var pushedBall  = heldBalls[index];

            // Check if any running animations to avoid conflicts
            if (this.gameActive && runningAnimations.Count == 0 && game.PushBall(pushedBall))
            {
                var ballHolder = ballHolders[index];
                uxMainCanvas.Children.Add(pushedBall);

                // TODO2: Trigger animation for ball and after animation is triggered

                PointAnimationUsingPath ballAnimation = new PointAnimationUsingPath();
                PathGeometry            animationPath = new PathGeometry();
                PathFigure pFigure = new PathFigure();
                pFigure.StartPoint = PointCanvas.GetTopLeft(ballHolder);
                //PathFigureCollection pfc = FindResource("RectanglePathFigureCollection") as PathFigureCollection;
                UIElement targetPanel = isPlayerOne ? ((UIElement)seesaw.leftBallPanel) : seesaw.rightBallPanel;
                Point     endPoint    = new Point(
                    Canvas.GetLeft(seesaw) + Canvas.GetLeft(seesaw.uxBalanceCanvas) + Canvas.GetLeft(targetPanel),
                    Canvas.GetTop(seesaw) + Canvas.GetTop(seesaw.uxBalanceCanvas) + Canvas.GetTop(targetPanel)
                    );
                pFigure.Segments.Add(ComputeCurve(pFigure.StartPoint, endPoint, velocity));

                animationPath.Figures.Add(pFigure);
                // Freeze the PathGeometry for performance benefits.
                animationPath.Freeze();

                ballAnimation.PathGeometry = animationPath;
                ballAnimation.BeginTime    = TimeSpan.FromSeconds(0);
                ballAnimation.Duration     = new Duration(TimeSpan.FromSeconds(0.75));
                ballAnimation.AutoReverse  = false;

                Storyboard.SetTarget(ballAnimation, pushedBall);
                Storyboard.SetTargetProperty(ballAnimation, new PropertyPath("(TopLeft)"));
                Storyboard ballMove = new Storyboard();
                ballMove.Children.Add(ballAnimation);
                runningAnimations.Add(ballMove);

                ballMove.Completed += delegate
                {
                    selectingBall = false;
                    uxMainCanvas.Children.Remove(pushedBall);
                    runningAnimations.Remove(ballMove);
                    (pushedBall as Bird).IsFlying = false;
                    // Reset ball move animation
                    pushedBall.BeginAnimation(SeesawObject.TopLeftProperty, null);
                    game.AddBallToBalance(pushedBall, isPlayerOne);
                };
                selectingBall = true;
                ballMove.Begin();
                // TODO2: Trigger animation for ball and after animation is triggered
            }
        }
        void addAPathJust(string gName, EllipseGeometry animatedEllipseGeometry, Canvas mainPanel, Brush brush, Point[] m_psCAMINHO, Point[] m_psFigFinal)
        {
            int Ynum = m_rr.Next((int)mainPanel.Height);
            int Xnum = m_rr.Next((int)mainPanel.Width);
            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(animatedEllipseGeometry.Center.X, animatedEllipseGeometry.Center.Y);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            // Point[] m_ps = { new Point(123, 42), new Point(923, 43), new Point(1858, 52), new Point(1846, 960), new Point(948, 968), new Point(103, 956), new Point(124, 47) };
            for (int i = 0; i < m_psCAMINHO.Length; i++)
            {
                pBezierSegment.Points.Add(m_psCAMINHO[i]);
            }
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal++ % m_psFigFinal.Length]);
            //pBezierSegment.Points.Add(new Point(35 + Xnum, 0 + Ynum ));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);


            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a PointAnimationgUsingPath to move
            // the EllipseGeometry along the animation path.
            PointAnimationUsingPath centerPointAnimation =
                new PointAnimationUsingPath();

            centerPointAnimation.PathGeometry = animationPath;
            centerPointAnimation.Duration     = TimeSpan.FromSeconds(1 + m_rr.Next(18));
            centerPointAnimation.BeginTime    = TimeSpan.FromSeconds(1 + m_rr.Next(3));
            centerPointAnimation.IsCumulative = true;
            // centerPointAnimation.RepeatBehavior = RepeatBehavior.Forever;
            // centerPointAnimation.AutoReverse = true;



            // Set the animation to target the Center property
            // of the EllipseGeometry named "AnimatedEllipseGeometry".
            Storyboard.SetTargetName(centerPointAnimation, gName);
            Storyboard.SetTargetProperty(centerPointAnimation,
                                         new PropertyPath(EllipseGeometry.CenterProperty));

            // pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            //*** pathAnimationStoryboard.AutoReverse = true;
            pathAnimationStoryboard.Children.Add(centerPointAnimation);
        }
示例#4
0
        public override void ApplyFluidTheme(IDataFluidTheme theme)
        {
            if (LayerData.GeoType == VectorLayer.GEOTYPE_LINEAR)
            {
                foreach (var featurePair in Features)
                {
                    var    feature  = featurePair.Key;
                    var    geometry = featurePair.Value.Geometry as PathGeometry;
                    var    poly     = new Geometry.PointString(feature.GeoData);
                    double length   = poly.Length();
                    if (length < 10)
                    {
                        continue;
                    }

                    double velocity  = theme.GetVelocity(feature);
                    double time      = length / velocity;
                    double space     = 1 / theme.GetDensity(feature);
                    int    spotCount = (int)(length / space) + 1;
                    var    color     = theme.GetColor(feature);

                    for (int i = 0; i < spotCount; i++)
                    {
                        var pointAnimation = new PointAnimationUsingPath
                        {
                            PathGeometry   = geometry,
                            Duration       = new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000))),
                            RepeatBehavior = RepeatBehavior.Forever,
                            BeginTime      = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000))
                        };

                        var colorAnimation = new ColorAnimation(
                            fromValue: color.Item1,
                            toValue: color.Item2,
                            duration: new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000))))
                        {
                            RepeatBehavior = RepeatBehavior.Forever,
                            BeginTime      = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000))
                        };

                        double radius      = theme.GetDiameter(feature) / 2;
                        var    fill        = new SolidColorBrush(color.Item1);
                        var    spot        = new EllipseGeometry(new Point(), radius, radius);
                        var    spotDrawing = new GeometryDrawing(fill, null, spot);
                        this.AddOverlayChildren(spotDrawing);
                        spot.BeginAnimation(EllipseGeometry.CenterProperty, pointAnimation);
                        fill.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation);
                    }
                }
            }
        }
        /// <summary>
        /// Create animation for moving from start station to end station
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="way"></param>
        public void AnimatePath(List <Station> way)
        {
            int pathStartId = stationsPathMark.FindIndex(x => x.Name == startStationMark.Name);

            System.Windows.Shapes.Path movingObjectPath = new System.Windows.Shapes.Path();
            movingPoint.RadiusX = radius;
            movingPoint.RadiusY = radius;
            Panel.SetZIndex(movingObjectPath, 6);
            movingObjectPath.Data = movingPoint;
            movingObjectPath.Fill = (SolidColorBrush)(new BrushConverter().ConvertFrom("#F5B700"));

            canvasSubway.Children.Add(movingObjectPath);

            PathGeometry animationPath = new PathGeometry();
            PathFigure   pathWay       = new PathFigure();

            pathWay.StartPoint = subwayGraph.stations[pathStartId].stationLocation;
            PolyLineSegment pathLine   = new PolyLineSegment();
            List <Point>    pathPoints = DetalizePathDisplaying(way);

            for (int i = 0; i < pathPoints.Count; i++)
            {
                pathLine.Points.Add(pathPoints[i]);
            }
            pathWay.Segments.Add(pathLine);
            animationPath.Figures.Add(pathWay);

            PointAnimationUsingPath animation = new PointAnimationUsingPath();

            animation.PathGeometry = animationPath;
            if (way.Count <= 6)
            {
                animation.Duration = TimeSpan.FromSeconds(1);
            }
            else
            {
                animation.Duration = TimeSpan.FromSeconds(3.5);
            }

            Storyboard.SetTargetName(animation, "movingPoint");
            Storyboard.SetTargetProperty(animation, new PropertyPath(EllipseGeometry.CenterProperty));
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(animation);

            movingObjectPath.Loaded += delegate
            {
                pathAnimationStoryboard.Begin(this);
            };
        }
示例#6
0
        private static void AddFluid(DrawingMapLayer animationLayer, TongJi.Gis.Display.IDataFluidTheme theme, TongJi.Gis.IFeature f)
        {
            var    poly   = new TongJi.Geometry.Polyline(f.GeoData);
            double length = poly.Length;

            if (length < 10)
            {
                return;
            }

            // 生成PathGeometry
            var          points   = poly.Points.Select(p => new Point(p.x, p.y)).ToList();
            PathGeometry geometry = new PathGeometry();
            PathFigure   figure   = new PathFigure {
                StartPoint = points.First()
            };
            PolyLineSegment segment = new PolyLineSegment(points, true);

            figure.Segments.Add(segment);
            geometry.Figures.Add(figure);

            // 读取参数
            double velocity  = theme.GetVelocity(f);
            double time      = length / velocity;
            double space     = 1 / theme.GetDensity(f);
            int    spotCount = (int)(length / space) + 1;
            var    color     = theme.GetColor(f);

            // 应用动画
            for (int i = 0; i < spotCount; i++)
            {
                PointAnimationUsingPath paup = new PointAnimationUsingPath();
                paup.PathGeometry   = geometry;
                paup.Duration       = new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000)));
                paup.RepeatBehavior = RepeatBehavior.Forever;
                paup.BeginTime      = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000));

                ColorAnimation ca = new ColorAnimation(color.Item1, color.Item2, new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000))));
                ca.RepeatBehavior = RepeatBehavior.Forever;
                ca.BeginTime      = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000));

                double          radius      = theme.GetDiameter(f) / 2;
                var             fill        = new SolidColorBrush(color.Item1);
                EllipseGeometry spot        = new EllipseGeometry(new Point(), radius, radius);
                GeometryDrawing spotDrawing = new GeometryDrawing(fill, null, spot);
                animationLayer.AddOverlayChildren(spotDrawing);
                spot.BeginAnimation(EllipseGeometry.CenterProperty, paup);
                fill.BeginAnimation(SolidColorBrush.ColorProperty, ca);
            }
        }
示例#7
0
        private void StartAnimation()
        {
            // Path1 animation:
            path1.Freeze(); // For performance benefits.
            PointAnimationUsingPath pa =
                new PointAnimationUsingPath();

            pa.PathGeometry   = path1;
            pa.Duration       = TimeSpan.FromSeconds(5);
            pa.RepeatBehavior = RepeatBehavior.Forever;
            circle1.BeginAnimation(
                EllipseGeometry.CenterProperty, pa);

            // Path2 animation:
            path2.Freeze(); // For performance benefits.
            DoubleAnimationUsingPath daPath =
                new DoubleAnimationUsingPath();

            daPath.Duration          = TimeSpan.FromSeconds(5);
            daPath.RepeatBehavior    = RepeatBehavior.Forever;
            daPath.AccelerationRatio = 0.6;
            daPath.DecelerationRatio = 0.4;
            daPath.AutoReverse       = true;
            daPath.PathGeometry      = path2;
            daPath.Source            = PathAnimationSource.X;
            circle2.BeginAnimation(
                Canvas.LeftProperty, daPath);
            daPath                   = new DoubleAnimationUsingPath();
            daPath.Duration          = TimeSpan.FromSeconds(5);
            daPath.RepeatBehavior    = RepeatBehavior.Forever;
            daPath.AccelerationRatio = 0.6;
            daPath.DecelerationRatio = 0.4;
            daPath.AutoReverse       = true;
            daPath.PathGeometry      = path2;
            daPath.Source            = PathAnimationSource.Y;
            circle2.BeginAnimation(
                Canvas.TopProperty, daPath);
            double          nRotation = 360 * (224 + Math.Sqrt(225 * 225 + 88 * 88)) / 2 / Math.PI / 25;
            DoubleAnimation da        = new DoubleAnimation(
                0, nRotation, TimeSpan.FromSeconds(5));

            da.RepeatBehavior    = RepeatBehavior.Forever;
            da.AutoReverse       = true;
            da.AccelerationRatio = 0.6;
            da.DecelerationRatio = 0.4;
            circle2Rotate.BeginAnimation(
                RotateTransform.AngleProperty, da);
        }
示例#8
0
        /// <summary>
        /// Funkja przygotowywująca animację na podstawie rozmiaru obiektu canvas
        /// </summary>
        /// <param name="geometry">Aktualny obiekt geometry</param>
        private void PrepareAnimation(EllipseGeometry geometry)
        {
            double space = playField.ActualWidth / baloons;

            j += (int)space + 50;
            if (j > playField.ActualWidth)
            {
                j = Convert.ToInt32(j % playField.ActualWidth);
            }

            geometry.Center = new Point(j, -50);
            up             = new PointAnimationUsingPath();
            pBezierSegment = new PolyBezierSegment();
            animationPath  = new PathGeometry();
            pFigure        = new PathFigure();

            pFigure.StartPoint = new Point(j, -50);
            for (int i = 0; (i < playField.ActualHeight); i += 25)
            {
                int randomSign = random.Next(1);
                if (randomSign == 0)
                {
                    pBezierSegment.Points.Add(new Point(j - random.Next(30), i));
                }
                else if (randomSign == 1)
                {
                    pBezierSegment.Points.Add(new Point(j + random.Next(30), i));
                }
            }
            pBezierSegment.Points.Add(new Point(j, playField.ActualHeight + 50));

            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);
            up.PathGeometry = animationPath;
            if (timesIndex != times.Count)
            {
                up.BeginTime = TimeSpan.FromSeconds(Convert.ToInt32(times[timesIndex]));
                timesIndex++;
            }

            up.Duration       = TimeSpan.FromSeconds(10);
            up.SpeedRatio     = 0.5;
            up.RepeatBehavior = RepeatBehavior.Forever;
            animationPath.Freeze();
            geometry.BeginAnimation(EllipseGeometry.CenterProperty, up);
        }
        public void AutoTurnPage(CornerOrigin fromCorner, int duration)
        {
            if (Status != PageStatus.None)
            {
                return;
            }
            if (duration <= 0)
            {
                return;
            }
            Status = PageStatus.TurnAnimation;

            UIElement source = this as UIElement;

            this.BeginAnimation(BookPage.CornerPointProperty, null);

            Point startPoint = OriginToPoint(this, fromCorner);
            Point endPoint   = OriginToOppositePoint(this, fromCorner);

            CornerPoint = startPoint;
            origin      = fromCorner;

            BezierSegment bs =
                new BezierSegment(startPoint, new Point(endPoint.X + (startPoint.X - endPoint.X) / 3, 250), endPoint, true);

            PathGeometry path   = new PathGeometry();
            PathFigure   figure = new PathFigure();

            figure.StartPoint = startPoint;
            figure.Segments.Add(bs);
            figure.IsClosed = false;
            path.Figures.Add(figure);

            PointAnimationUsingPath anim =
                new PointAnimationUsingPath();

            anim.PathGeometry      = path;
            anim.Duration          = new Duration(TimeSpan.FromMilliseconds(duration));
            anim.AccelerationRatio = 0.6;

            anim.CurrentTimeInvalidated += anim_CurrentTimeInvalidated;
            anim.Completed += anim_Completed;
            this.BeginAnimation(BookPage.CornerPointProperty, anim);
        }
示例#10
0
        private void Path_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //var animation = new PointAnimationUsingPath
            //{
            //    Duration = TimeSpan.FromSeconds(2),
            //    PathGeometry = (PathGeometry)FindResource("path1"),
            //};
            //ellipse1.BeginAnimation(EllipseGeometry.CenterProperty, animation);
            var pathGeometry = CreatePath(ellipse1.Center, e.GetPosition(path2));

            var animation = new PointAnimationUsingPath
            {
                Duration     = TimeSpan.FromSeconds(2),
                PathGeometry = pathGeometry,
                FillBehavior = FillBehavior.HoldEnd
            };

            ellipse1.BeginAnimation(EllipseGeometry.CenterProperty, animation);
        }
示例#11
0
        public override void ApplyFluidTheme(IDataFluidTheme theme)
        {
            if (LayerData.GeoType == "2")
            {
                foreach (var feature in Features)
                {
                    var    f        = feature.Key;
                    var    geometry = feature.Value.Geometry as PathGeometry;
                    var    poly     = new Geometry.Polyline(f.GeoData);
                    double length   = poly.Length;
                    if (length < 10)
                    {
                        continue;
                    }
                    double velocity  = theme.GetVelocity(f);
                    double time      = length / velocity;
                    double space     = 1 / theme.GetDensity(f);
                    int    spotCount = (int)(length / space) + 1;
                    var    color     = theme.GetColor(f);

                    for (int i = 0; i < spotCount; i++)
                    {
                        PointAnimationUsingPath paup = new PointAnimationUsingPath();
                        paup.PathGeometry   = geometry;
                        paup.Duration       = new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000)));
                        paup.RepeatBehavior = RepeatBehavior.Forever;
                        paup.BeginTime      = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000));

                        ColorAnimation ca = new ColorAnimation(color.Item1, color.Item2, new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000))));
                        ca.RepeatBehavior = RepeatBehavior.Forever;
                        ca.BeginTime      = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000));

                        double          radius      = theme.GetDiameter(f) / 2;
                        var             fill        = new SolidColorBrush(color.Item1);
                        EllipseGeometry spot        = new EllipseGeometry(new Point(), radius, radius);
                        GeometryDrawing spotDrawing = new GeometryDrawing(fill, null, spot);
                        this.AddOverlayChildren(spotDrawing);
                        spot.BeginAnimation(EllipseGeometry.CenterProperty, paup);
                        fill.BeginAnimation(SolidColorBrush.ColorProperty, ca);
                    }
                }
            }
        }
        /// <summary>
        /// Calibration method.
        /// </summary>
        private void StartCalibration(object sender, EventArgs e)
        {
            if (CalibrationStarted)
            {
                return;
            }
            CalibrationStarted = true;

            pipeline.RunAsync();

            var segment = new PolyLineSegment();

            allCalibrationLines.ForEach(line => segment.Points.Add(new Point(line.X2, line.Y2)));
            var pathFigure = new PathFigure();

            pathFigure.StartPoint = new Point(allCalibrationLines.First().X1, allCalibrationLines.First().Y1);
            pathFigure.Segments.Add(segment);
            var animationPath = new PathGeometry();

            animationPath.Figures.Add(pathFigure);
            animationPath.Freeze();

            var centerPointAnimation = new PointAnimationUsingPath();

            centerPointAnimation.PathGeometry = animationPath;
            centerPointAnimation.Duration     = Duration;

            Storyboard.SetTargetName(centerPointAnimation, nameof(EllipseGeometryCalibrationCircle));//Storyboard.SetTarget method not working
            Storyboard.SetTargetProperty(centerPointAnimation, new PropertyPath(EllipseGeometry.CenterProperty));

            pathAnimationStoryboard.Children.Add(centerPointAnimation);
            //pathAnimationStoryboard.Completed += CalibrationCompleted;
            pathAnimationStoryboard.AutoReverse    = true;
            pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            pathAnimationStoryboard.Begin(this);
            CompositionTarget.Rendering += CaptureCalibrationCircleCoordinate;
        }
示例#13
0
        private void AnimateMovement(Move move)
        {
            foreach (var elem in BoardCanvasElements.Where(e => e.Geometry is EllipseGeometry && e.X == move.OldPiece.Row && e.Y == move.OldPiece.Column).ToList())
            {
                var x = elem.Geometry;
                if (Window.FindName("MyAnimatedEllipseGeometry") != null)
                {
                    Window.UnregisterName("MyAnimatedEllipseGeometry");
                }
                Window.RegisterName("MyAnimatedEllipseGeometry", x);

                PathGeometry animationPath = new PathGeometry();
                Point        position      = new Point(move.OldPiece.Column, move.OldPiece.Row);
                PathFigure   pFigure       = new PathFigure();
                pFigure.StartPoint = new Point(0, 0);
                PolyLineSegment lineSegment = new PolyLineSegment();
                double          xDiff, yDiff;
                foreach (var beatPositionPiece in move.BeatedPieces?.Skip(1) ?? new List <BeatedPiece>())
                {
                    xDiff = ((skipSize * beatPositionPiece.BeatPieceColumn + skipSize / 2) - (skipSize * position.X + skipSize / 2));
                    yDiff = (skipSize * (Game.Board.Size - 1 - beatPositionPiece.BeatPieceRow) + skipSize / 2) - (skipSize * (Game.Board.Size - 1 - position.Y) + skipSize / 2);
                    if (lineSegment.Points.Count > 0)
                    {
                        lineSegment.Points.Add(new Point(lineSegment.Points.Last().X + xDiff, lineSegment.Points.Last().Y + yDiff));
                    }
                    else
                    {
                        lineSegment.Points.Add(new Point(xDiff, yDiff));
                    }
                    position = new Point(beatPositionPiece.BeatPieceColumn, beatPositionPiece.BeatPieceRow);
                }
                xDiff = (skipSize * move.NewPiece.Column + skipSize / 2) - (skipSize * position.X + skipSize / 2);
                yDiff = (skipSize * (Game.Board.Size - 1 - move.NewPiece.Row) + skipSize / 2) - (skipSize * (Game.Board.Size - 1 - position.Y) + skipSize / 2);
                if (lineSegment.Points.Count > 0)
                {
                    lineSegment.Points.Add(new Point(lineSegment.Points.Last().X + xDiff, lineSegment.Points.Last().Y + yDiff));
                }
                else
                {
                    lineSegment.Points.Add(new Point(xDiff, yDiff));
                }
                pFigure.Segments.Add(lineSegment);
                animationPath.Figures.Add(pFigure);
                animationPath.Freeze();


                PointAnimationUsingPath myPointAnimation = new PointAnimationUsingPath();
                myPointAnimation.Duration     = TimeSpan.FromSeconds((double)MoveAnimationTime / 100 * ((move.BeatedPieces?.Count()) ?? 1));
                myPointAnimation.FillBehavior = FillBehavior.Stop;
                myPointAnimation.PathGeometry = animationPath;

                AnimationCompleted          = false;
                myPointAnimation.Completed += delegate
                {
                    DrawMoveMovement(move, elem);
                    Thread.Sleep(100);
                    AnimationCompleted = true;
                };

                // Set the animation to target the Center property
                // of the object named "MyAnimatedEllipseGeometry."
                Storyboard.SetTargetName(myPointAnimation, "MyAnimatedEllipseGeometry");
                Storyboard.SetTargetProperty(
                    myPointAnimation, new PropertyPath(EllipseGeometry.CenterProperty));

                // Create a storyboard to apply the animation.
                Storyboard ellipseStoryboard             = new Storyboard();
                ellipseStoryboard.Children.Add(myPointAnimation);
                ellipseStoryboard.Begin(Window);
                elem.Geometry = x;
            }
        }
        private void GeneratePath(int l, int t)
        {
            NameScope.SetNameScope(this, new NameScope());

            PathGeometry pg     = new PathGeometry();
            PathFigure   figure = new PathFigure();

            figure.StartPoint = new Point(0, 0);
            figure.Segments.Add(new LineSegment(new Point(100, 0), true));
            figure.Segments.Add(new LineSegment(new Point(100, 50), true));
            figure.Segments.Add(new LineSegment(new Point(0, 50), true));
            figure.IsClosed = true;
            figure.IsFilled = true;

            pg.Figures.Add(figure);

            Storyboard board = new Storyboard();

            PointAnimationUsingPath pau = new PointAnimationUsingPath();

            pau.PathGeometry   = pg;
            pau.Duration       = TimeSpan.FromSeconds(5);
            pau.RepeatBehavior = RepeatBehavior.Forever;
            board.Children.Add(pau);

            Path path = new Path();

            path.Data = pg;

            LinearGradientBrush lgb = new LinearGradientBrush();

            lgb.StartPoint = new Point(0.5, 0);
            lgb.EndPoint   = new Point(0.5, 1);
            lgb.GradientStops.Add(new GradientStop(Colors.Black, 0));
            lgb.GradientStops.Add(new GradientStop(ToMediaColor("FF0FA3C9"), 0.523));
            lgb.GradientStops.Add(new GradientStop(ToMediaColor("FF0FA3C9"), 1));
            lgb.GradientStops.Add(new GradientStop(ToMediaColor("FF556A79"), 0.993));
            lgb.GradientStops.Add(new GradientStop(ToMediaColor("FF1E96B7"), 1));

            path.Stroke          = Brushes.Gray;
            path.StrokeThickness = 1;
            path.Fill            = lgb;

            Path            ellipse         = new Path();
            EllipseGeometry ellipseGeometry = new EllipseGeometry();

            ellipseGeometry.Center  = new Point(5, 5);
            ellipseGeometry.RadiusX = 6;
            ellipseGeometry.RadiusY = 6;
            this.RegisterName("ell", ellipseGeometry);
            ellipse.Data = ellipseGeometry;
            ellipse.Fill = Brushes.Orange;

            Storyboard.SetTargetName(pau, "ell");
            Storyboard.SetTargetProperty(pau, new PropertyPath(EllipseGeometry.CenterProperty));



            this.canvas.Children.Add(path);
            this.canvas.Children.Add(ellipse);

            path.Margin    = new Thickness(_offsetX * l, _offsetY * t, 0, 0);
            ellipse.Margin = new Thickness(_offsetX * l, _offsetY * t, 0, 0);

            //Canvas.SetLeft(path, _offsetX * l);
            //Canvas.SetLeft(ellipse, _offsetX * l);

            //Canvas.SetTop(path, _offsetY * t);
            //Canvas.SetTop(ellipse, _offsetY * t);

            board.Begin(this);
        }
        void addAPath(string gName, EllipseGeometry animatedEllipseGeometry, Canvas mainPanel, Brush brush)
        {
            // Create a Path element to display the geometry.
            Path ellipsePath = new Path();

            ellipsePath.Data   = animatedEllipseGeometry;
            ellipsePath.Fill   = brush;
            ellipsePath.Margin = new Thickness(15);

            mainPanel.Children.Add(ellipsePath);
            int Ynum = rr.Next((int)mainPanel.Height);
            int Xnum = rr.Next((int)mainPanel.Width);
            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(animatedEllipseGeometry.Center.X, animatedEllipseGeometry.Center.Y);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            // Point[] m_ps = { new Point(123, 42), new Point(923, 43), new Point(1858, 52), new Point(1846, 960), new Point(948, 968), new Point(103, 956), new Point(124, 47) };
            Point[] m_ps = { new Point(118, 95), new Point(427, 41), new Point(870, 31), new Point(1348, 44), new Point(1754, 77), new Point(1842, 222), new Point(1858, 565), new Point(1787, 843), new Point(1519, 914), new Point(1219, 922), new Point(915, 924), new Point(624, 911), new Point(377, 919), new Point(200, 890), new Point(130, 714), new Point(156, 498), new Point(271, 392), new Point(504, 336), new Point(849, 327), new Point(1063, 348), new Point(1128, 481), new Point(1080, 581), new Point(917, 599), new Point(835, 542), new Point(823, 414), new Point(959, 371), new Point(999, 471) };
            for (int i = 0; i < m_ps.Length; i++)
            {
                pBezierSegment.Points.Add(m_ps[i]);
            }
            pBezierSegment.Points.Add(m_psFELIZNATAL[contaFelizNatal % m_psFELIZNATAL.Length]);
            pBezierSegment.Points.Add(m_psFELIZNATAL[contaFelizNatal % m_psFELIZNATAL.Length]);
            pBezierSegment.Points.Add(m_psFELIZNATAL[contaFelizNatal % m_psFELIZNATAL.Length]);
            pBezierSegment.Points.Add(m_psFELIZNATAL[contaFelizNatal % m_psFELIZNATAL.Length]);
            pBezierSegment.Points.Add(m_psFELIZNATAL[contaFelizNatal++ % m_psFELIZNATAL.Length]);
            //pBezierSegment.Points.Add(new Point(35 + Xnum, 0 + Ynum ));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);


            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a PointAnimationgUsingPath to move
            // the EllipseGeometry along the animation path.
            PointAnimationUsingPath centerPointAnimation =
                new PointAnimationUsingPath();

            centerPointAnimation.PathGeometry = animationPath;
            centerPointAnimation.Duration     = TimeSpan.FromSeconds(1 + rr.Next(18));
            centerPointAnimation.BeginTime    = TimeSpan.FromSeconds(1 + rr.Next(3));
            centerPointAnimation.IsCumulative = true;
            // centerPointAnimation.RepeatBehavior = RepeatBehavior.Forever;
            // centerPointAnimation.AutoReverse = true;


            Action aa = new Action(mudaCores);

            // Set the animation to target the Center property
            // of the EllipseGeometry named "AnimatedEllipseGeometry".
            Storyboard.SetTargetName(centerPointAnimation, gName);
            Storyboard.SetTargetProperty(centerPointAnimation,
                                         new PropertyPath(EllipseGeometry.CenterProperty));

            // pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            //*** pathAnimationStoryboard.AutoReverse = true;
            pathAnimationStoryboard.Children.Add(centerPointAnimation);


            // Start the Storyboard when ellipsePath is loaded.
            ellipsePath.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                // Start the storyboard.
                pathAnimationStoryboard.Begin(this);
            };
            pathAnimationStoryboard.Completed += PathAnimationStoryboard_Completed;
        }
示例#16
0
        public PointAnimationUsingPathExample()
        {
            // Create a NameScope for the page so that
            // we can use Storyboards.
            NameScope.SetNameScope(this, new NameScope());

            // Create the EllipseGeometry to animate.
            EllipseGeometry animatedEllipseGeometry =
                new EllipseGeometry(new Point(10, 100), 15, 15);

            // Register the EllipseGeometry's name with
            // the page so that it can be targeted by a
            // storyboard.
            this.RegisterName("AnimatedEllipseGeometry", animatedEllipseGeometry);

            // Create a Path element to display the geometry.
            Path ellipsePath = new Path();

            ellipsePath.Data   = animatedEllipseGeometry;
            ellipsePath.Fill   = Brushes.Blue;
            ellipsePath.Margin = new Thickness(15);

            // Create a Canvas to contain ellipsePath
            // and add it to the page.
            Canvas mainPanel = new Canvas();

            mainPanel.Width  = 400;
            mainPanel.Height = 400;
            mainPanel.Children.Add(ellipsePath);
            this.Content = mainPanel;

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(10, 100);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            pBezierSegment.Points.Add(new Point(35, 0));
            pBezierSegment.Points.Add(new Point(135, 0));
            pBezierSegment.Points.Add(new Point(160, 100));
            pBezierSegment.Points.Add(new Point(180, 190));
            pBezierSegment.Points.Add(new Point(285, 200));
            pBezierSegment.Points.Add(new Point(310, 100));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a PointAnimationgUsingPath to move
            // the EllipseGeometry along the animation path.
            PointAnimationUsingPath centerPointAnimation =
                new PointAnimationUsingPath();

            centerPointAnimation.PathGeometry   = animationPath;
            centerPointAnimation.Duration       = TimeSpan.FromSeconds(5);
            centerPointAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation to target the Center property
            // of the EllipseGeometry named "AnimatedEllipseGeometry".
            Storyboard.SetTargetName(centerPointAnimation, "AnimatedEllipseGeometry");
            Storyboard.SetTargetProperty(centerPointAnimation,
                                         new PropertyPath(EllipseGeometry.CenterProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            pathAnimationStoryboard.AutoReverse    = true;
            pathAnimationStoryboard.Children.Add(centerPointAnimation);

            // Start the Storyboard when ellipsePath is loaded.
            ellipsePath.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                // Start the storyboard.
                pathAnimationStoryboard.Begin(this);
            };
        }
示例#17
0
        private void OnSkaterChanged(PairsRaceColor color, IActiveTrackRaceViewModel oldRace, IActiveTrackRaceViewModel newRace, Style style)
        {
            if (Distance == null || PathProvider == null || canvas == null)
            {
                return;
            }

            TrackCompetitorStoryboard storyboard;

            if (storyboards.TryGetValue(color, out storyboard))
            {
                storyboard.DetachAndStop();
                storyboards.Remove(color);
            }

            Shape shape;

            if (skaters.TryGetValue(color, out shape))
            {
                canvas.Children.Remove(shape);
                skaters.Remove(color);
            }

            if (oldRace != null)
            {
                oldRace.TimeInvalidReasonChanged -= RaceTimeInvalidReasonChanged;
            }

            if (newRace == null)
            {
                return;
            }

            newRace.TimeInvalidReasonChanged += RaceTimeInvalidReasonChanged;
            if (newRace.TimeInvalidReason != null)
            {
                return;
            }

            var path = PathProvider.CreatePath(Distance, newRace.Lane);

            if (path == null)
            {
                return;
            }

            var ellipse = new EllipseGeometry(path.Figures[0].StartPoint, 2, 2);
            var ball    = new Path
            {
                Data  = ellipse,
                Style = style
            };

            Panel.SetZIndex(ball, 4 - newRace.Color);
            NameScope.SetNameScope(ball, new NameScope());
            ball.RegisterName("Ellipse", ellipse);
            canvas.Children.Add(ball);

            var animation = new PointAnimationUsingPath
            {
                Duration     = TimeSpan.FromSeconds(PathProvider.Calculator.Length(Distance)),
                PathGeometry = path
            };

            Storyboard.SetTargetName(animation, "Ellipse");
            Storyboard.SetTargetProperty(animation, new PropertyPath(EllipseGeometry.CenterProperty));
            storyboard = new TrackCompetitorStoryboard(newRace, PathProvider.Calculator);
            storyboard.Children.Add(animation);
            storyboard.AttachAndBegin(ball);

            skaters[color]     = ball;
            storyboards[color] = storyboard;
        }
示例#18
0
        public void AnimateSpaceShipPath(SpaceShip spaceShip, double distance, string ownerColor, PointCollection pointCol)
        {
            // Create a NameScope for the page so that
            // we can use Storyboards.
            NameScope.SetNameScope(this, new NameScope());

            // Create the EllipseGeometry to animate.
            EllipseGeometry animatedEllipseGeometry =
                new EllipseGeometry(pointCol[0], 1, 1);

            // Register the EllipseGeometry's name with
            // the page so that it can be targeted by a
            // storyboard.
            this.RegisterName("AnimatedEllipseGeometry", animatedEllipseGeometry);

            // Create a Path element to display the geometry.
            Path ellipsePath = new Path
            {
                Data = animatedEllipseGeometry,
                Fill = (SolidColorBrush) new BrushConverter().ConvertFromString(ownerColor),
            };

            spaceShipDict.Add(spaceShip, ellipsePath);

            BackgroundCanvas.Children.Add(ellipsePath);

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = pointCol[0];
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            for (int i = 1; i < pointCol.Count; i++)
            {
                pBezierSegment.Points.Add(pointCol[i]);
                pBezierSegment.Points.Add(pointCol[i]);
                pBezierSegment.Points.Add(pointCol[i]);
            }

            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a PointAnimationgUsingPath to move
            // the EllipseGeometry along the animation path.
            PointAnimationUsingPath centerPointAnimation =
                new PointAnimationUsingPath();

            centerPointAnimation.PathGeometry = animationPath;
            double speedControl = 1.97;

            centerPointAnimation.Duration       = TimeSpan.FromMilliseconds((distance / (0.125)) * speedControl);
            centerPointAnimation.RepeatBehavior = new RepeatBehavior(1);

            // Set the animation to target the Center property
            // of the EllipseGeometry named "AnimatedEllipseGeometry".
            Storyboard.SetTargetName(centerPointAnimation, "AnimatedEllipseGeometry");
            Storyboard.SetTargetProperty(centerPointAnimation,
                                         new PropertyPath(EllipseGeometry.CenterProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.RepeatBehavior = new RepeatBehavior(1);
            pathAnimationStoryboard.AutoReverse    = false;
            pathAnimationStoryboard.Children.Add(centerPointAnimation);

            // Start the Storyboard when ellipsePath is loaded.
            ellipsePath.Loaded += delegate(object sender2, RoutedEventArgs evArgs)
            {
                // Start the storyboard.
                pathAnimationStoryboard.Begin(this);
            };
        }