예제 #1
0
        private void FillCanvasWithTiles(MozaicCanvas canvas)
        {
            var tileSize = 15;

             var clientWidth = canvas.Width;
             var clientHeight = canvas.Height;

             var tilesCountHor = clientWidth / tileSize;
             var tilesCountVer = clientHeight / tileSize;

             var gridWidth = clientWidth / tilesCountHor;
             var gridHeight = clientHeight / tilesCountVer;

             var brush1 = new SolidColorBrush(Colors.DimGray);
             var brush2 = new SolidColorBrush(Colors.DarkGray);

             var brushes = new Brush[] {brush1, brush2};

             var randomizer = new Random(0);

             for (int i = 0; i < tilesCountVer; i++)
             {
                 for (int j = 0; j < tilesCountHor; j++)
                 {
                     var positionX = gridWidth * j;
                     var positionY = gridHeight * i;
                     var visual = new DrawingVisual();
                     var dc = visual.RenderOpen();

                     var selectedBrush = brushes[randomizer.Next(2)];

                     dc.DrawRectangle(selectedBrush, new Pen(new SolidColorBrush(Colors.Black), 0.3), new Rect(positionX, positionY, gridWidth, gridHeight));

                     dc.Close();
                     canvas.AddVisual(visual);
                 }
             }
        }
예제 #2
0
        private void SetCanvasSize(MozaicCanvas mozaicCanvas)
        {
            mozaicCanvas.Clear();

            mozaicCanvas.Width = CanvasWidth;
            mozaicCanvas.Height = CanvasHeight;
        }