How to animate a polygon? (Read: Animate the outline to change shape)

Hello!

I am currently working on a Silverlight project, and I would like to animate a simple polygon shape (actually a trapezoid). In particular, I would like to dynamically move two of the four points after an event has occurred. I need / need to resize and move one of the parallel sides to another position.

I admit that I am pretty new to Silverlight and have not found a source that could tell me that this is even possible, not to mention how this can be done.

I used animation before, so the general concept of storyboard and animation is not new to me. But how to transfer the polygon points to the animation? Are there alternatives that have a similar optical effect (like path animation)?
Is there a PropertyPath that I can use, like

P3AnimBack.SetValue(Storyboard.TargetPropertyProperty, 
    new PropertyPath("(Path.Data).
        (PathGeometry.Figures)[0].(PathFigure.Segments)[0].
        (BezierSegment.Point3)"));

as shown in Spot Animation in the Silverlight 3 Tutorial

Thanks to everyone in advance. :)

+3
source share
2 answers

I don't know anything about Silverlight or .NET animations in general, but Charles Petzold did something similar:

+4

, , , , :

Interlolations Silverlight - "" PointCollectionInterpolator.cs.

:

private void CreatePolygon(TextBox txtbx, string prop, Color curcol)
    {
        PointCollectionInterpolator pci = new PointCollectionInterpolator();
        pci.Points1 = new PointCollection() // Start Points
            {
                new Point(...),
                new Point(...),
                new Point(...),
                new Point(...),
            };

        pci.Points2 = new PointCollection() // End Points
            {
                new Point(...),
                new Point(...),
                new Point(...),
                new Point(...),
            };

        Polygon tmpply = new Polygon();
        LayoutRoot.Children.Add(tmpply);

        tmpply.Points = pci.InterpolatedPoints;

        DoubleAnimation animpci = new DoubleAnimation();
        animpci.Duration = someDuration;
        animpci.From = 0.0;
        animpci.To = 1.0;
        Storyboard.SetTarget(animpci, pci);
        Storyboard.SetTargetProperty(animpci, new PropertyPath("(Progress)"));
        myStoryBoard.Children.Add(animpci);
    }

- . , , . (, 0.0...) , , , .

private void SomeEventHandler(object sender, RoutedEventArgs e) 
{
    PointCollectionInterpolator polygonPCI = 
            this.referenceToPointCollectionInterpolator;
    polygonPCI.Points1 = polygonPCI.Points2;
    polygonPCI.Progress = 0.0;
    polygonPCI.Points2 = getNewEndPoints();
    myStoryBoard.Begin();
}

Points1 Points2 StartPoints EndPoints . , .:)

+1

Source: https://habr.com/ru/post/1715422/


All Articles