private List <DistrictCell> GenerateDistrictCells(VoronoiDiagram voronoi)
        {
            //Create a district cell from the voronoi cells
            var districtCells = new List <DistrictCell>();

            foreach (var cell in voronoi.GetCellsInBounds())
            {
                //ignore cells that are not valid
                if (cell.Edges.Count < 2)
                {
                    continue;
                }

                districtCells.Add(DistrictCell.FromCell(cell, _citySettings.DistrictSettings[0].Type));
            }


            //tag random cells based on the settings for each district
            foreach (var setting in _citySettings.DistrictSettings)
            {
                for (int i = 0; i < setting.Frequency; ++i)
                {
                    //Get a random start cell from the voronoi
                    var startCell = districtCells.GetRandomValue();

                    //size is a ratio of the width and length of the plane
                    var size = setting.Size * ((voronoi.Bounds.Right + voronoi.Bounds.Bottom) / 8);

                    //tag cell
                    districtCells.TagCells(startCell, size, setting.Type);
                }
            }

            return(districtCells);
        }
예제 #2
0
        private void DrawVoronoiDiagram()
        {
            var pointColor    = Color.FromRgb(25, 25, 25);
            var triangleColor = Color.FromRgb(50, 50, 50);
            var lineColor     = Color.FromRgb(22, 22, 22);

            if (_voronoiDiagram != null)
            {
                //Show Bounds
                if (ShowBounds == true)
                {
                    _drawService.DrawRectangle(_voronoiDiagram.Bounds, Colors.Red);
                }

                //Draw Triangulation
                if (_voronoiDiagram.Triangulation != null)
                {
                    foreach (var t in _voronoiDiagram.Triangulation)
                    {
                        //Fill triangles in a random color

                        if (ColorTriangles)
                        {
                            _drawService.DrawPolygon(t, Extensions.Extensions.RandomColor());
                        }

                        if (DrawTriangles == true)
                        {
                            _drawService.DrawTriangle(t, triangleColor);
                        }
                    }
                }


                //Voronoi Colors
                if (_voronoiDiagram.VoronoiCells != null && ColorVoronoi.Value == true || DrawVoronoi.Value == true)
                {
                    foreach (var cell in _voronoiDiagram.GetCellsInBounds())
                    {
                        var c = (ColorVoronoi == true) ? _baseColor.GetRandomColorOffset(0.2) : lineColor;
                        _drawService.DrawCell(cell, c, ColorVoronoi.Value);
                    }
                }
            }

            //Draw Points
            if (DrawPoints == true)
            {
                foreach (var p in _points)
                {
                    _drawService.DrawPoint(p, PointSize, pointColor);
                    if (ShowPointInfo == true)
                    {
                        _drawService.DrawText(p.ToString(), pointColor, p);
                    }
                }
            }
        }