Example #1
        /// <summary>
        /// Keep generating roads until branches are zero
        /// </summary>
        private List<Road> GenerateRoad(List<Road> roads,List<Road> inner , Road startLine ,Road endLine, int branches)
            //find a new start and end point
            var start = startLine.Center();
            var end = endLine.Center();

            //When an intersection occurs break the line
            HandlePossibleRoadIntersections(new Line(start,end),startLine,endLine, roads, inner);

            //reduce branches to end recursion
            if (branches + 1 <= 0)
                return roads;

            //From the pool of lines choose 2 random ones that aren't the same
            var road1 = roads.GetRandomValue();
            var road2 = roads.GetRandomValue();
            //make sure both are unique
            while (road1 == road2)
                road2 = roads.GetRandomValue();

            //generate a new road by connecting 2 roads
            return GenerateRoad(roads, inner, road1, road2, branches);
Example #2
        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)


            //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;