Exemplo n.º 1
0
        public async void RunTestBalls()
        {
            // Geometry
            int sideLengthY = Dimension;
            int sideLengthX = sideLengthY * 2;
            XY  TopLeft     = new XY(0, 0);
            XY  BottomRight = new XY(sideLengthX, sideLengthY);

            // Polygon prototype (for RectangleShape)
            Polygon pProto = new Polygon
            {
                Stroke          = new SolidColorBrush(Colors.DarkGray),
                StrokeThickness = 2
            };

            // Bounding rectangle and associated Drawer
            RectangleShape  rA  = new RectangleShape(TopLeft, sideLengthX, sideLengthY);
            RectangleDrawer rdA = new RectangleDrawer(rA, pProto);

            rdA.AttachToCanvas(MainCanvas.Instance.TheCanvas);

            BouncingBallCollection bbc = new BouncingBallCollection(new BouncingBallFactory(TopLeft, BottomRight, 20, 80, 1, 5), _ballCount);

            _bbcd = new BouncingBallCollectionDrawer(bbc, MainCanvas.Instance.TheCanvas);

            // Main simulation loop
            for (int i = 1; i <= LoopCount; i++)
            {
                lock (_lock)
                {
                    _bbcd.BallDrawers.ForEach(b => b.MoveAndDraw());
                }
                await Task.Delay(DelayMs);
            }
        }
Exemplo n.º 2
0
        public BouncingBallCollectionDrawer(BouncingBallCollection balls, Canvas canvas)
        {
            _ballDrawers = new List <BouncingBallRenderer>();
            _balls       = balls;
            _canvas      = canvas;

            CreateDrawers(_balls.Balls);
        }