Chessmate
Chessmate

Reputation: 71

How to draw a Polyline Point for Point

Got a annoying Problem. How can i draw a "timed" Polyline?

I have a bunch of Points that will draw me a nice polyline. The challenge is that i want to draw it "slowly", with a selectable delay before the next point gets added. I'm sure you guys know how to make it, but I couldn't find anything on google or here.

My code:

    private void Button_Fire_P1_Click(object sender, RoutedEventArgs e)
    {
        double InputAngle = Slider_Angle_P1.Value;
        double InputSpeed = Slider_Speed_P1.Value;

        List<Point> P1points = new List<Point>();

        P1points = Projectile_Path_to_Right(1.0, 728.0, InputAngle, InputSpeed);
        int delay = Convert.ToInt32(InputSpeed);

        for (int i = 0; i < P1points.Count; i++)
        {
            Poly1.Points.Add(P1points[i]);
        }

        P1points.Clear();
    }

Edit: as you can see, my Polyline is created in the XAML, within a canvas.

  <Grid>
    <StackPanel Orientation="Vertical" Background="Gray">
        <Canvas x:Name="canvas" Width="1024" Height="728">
            <Rectangle x:Name="BarrellP1" Height="2" Width="40" Canvas.Top="728" Canvas.Left="0" Fill="Red"/>
            <Rectangle x:Name="BarrellP2" Height="2" Width="40" Canvas.Top="728" Canvas.Left="1020" Fill="Orange"/>
            <Polyline x:Name="Frame" Stroke="Black"/>
            <Polyline x:Name="Poly1" Stroke="Red"/>
            <Polyline x:Name="Poly2" Stroke="Orange"/>
        </Canvas>

Upvotes: 0

Views: 305

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32785

The challenge is that i want to draw it "slowly", with a selectable delay before the next point gets added.

I think you could add the task delay before Points.Add method. For example

for (int i = 0; i < P1points.Count; i++)
{
    await Task.Delay(TimeSpan.FromSeconds(1));
    Poly1.Points.Add(P1points[i]);
}

Upvotes: 1

Related Questions