void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            if (ellipses.Count == 0)
            {
                int halfCanvasWidth = (int)canvas.ActualWidth / 2;

                Random rnd = new Random();

                int count = rnd.Next(minEllipses, maxEllipses);

                for (int i = 0; i < count; i++)
                {
                    Ellipse ellipse = new Ellipse();
                    ellipse.Fill   = Brushes.LimeGreen;
                    ellipse.Width  = ellipseRadius;
                    ellipse.Height = ellipseRadius;

                    Canvas.SetLeft(ellipse, halfCanvasWidth + rnd.Next(-halfCanvasWidth, halfCanvasWidth));
                    Canvas.SetTop(ellipse, 0);

                    canvas.Children.Add(ellipse);

                    EllipseInfo info = new EllipseInfo(ellipse, speedRatio * rnd.Next(minStartingSpeed, maxStartingSpeed));

                    ellipses.Add(info);
                }
            }
            else
            {
                for (int i = 0; i < ellipses.Count - 1; i++)
                {
                    EllipseInfo info = ellipses[i];
                    double      top  = Canvas.GetTop(info.Ellipse);
                    Canvas.SetTop(info.Ellipse, top + 1 * info.VelocityY);

                    if (Top >= (canvas.ActualHeight - ellipseRadius * 2))
                    {
                        ellipses.Remove(info);
                    }
                    else
                    {
                        info.VelocityY += accelerationY;
                    }
                }

                if (ellipses.Count == 0)
                {
                    CompositionTarget.Rendering -= CompositionTarget_Rendering;
                    rendering = false;
                }
            }
        }
Esempio n. 2
0
        private void DrawEllipse(EllipseInfo e)
        {
            var ell = new System.Windows.Shapes.Ellipse();

            ell.StrokeThickness = 2;
            ell.Stroke          = Brushes.Black;
            Shapes.Ellipse myEll = new Shapes.Ellipse(new Vec2f(e.f1[0], e.f1[1]),
                                                      new Vec2f(e.f2[0], e.f2[1]), e.bigO);
            ell.Height = myEll.a * 2 * 100;
            ell.Width  = myEll.b * 2 * 100;

            panel.Children.Add(ell);
        }