コード例 #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);
            }
        }
コード例 #2
0
        private void DrawTiltedRect(int tilt)
        {
            RectangleShape rA     = new RectangleShape(new XY(Dimension / 2, Dimension / 2), Dimension / 3, Dimension / 5, tilt);
            Polygon        pProto = new Polygon
            {
                Stroke          = new SolidColorBrush(Colors.Black),
                StrokeThickness = 2,
                Fill            = new SolidColorBrush(Color.FromArgb(255, (byte)((255 * tilt) / 360), 0, 0))
            };

            RectangleDrawer rdA = new RectangleDrawer(rA, pProto);

            rdA.AttachToCanvas(MainCanvas.Instance.TheCanvas);
        }