Esempio n. 1
0
        private void BuildGalaxy()
        {
            var spiralPoints  = SpiralPoints();
            var poissonPoints = PoissonPoints();

            var enumerable = poissonPoints as Vector2[] ?? poissonPoints.ToArray();
            var stars      = enumerable.ToPoints();
            var del        = new Delaunator(stars);

            var delPoints = del.Points;

            del.ForEachVoronoiCell(cell =>
            {
                // Where the hell even is the star?
                var curStarPoint = delPoints[cell.Index].ToVector3();

                // Return if the star is outside of the galaxy
                if (OutsideGalaxy(curStarPoint, spiralPoints))
                {
                    return;
                }

                // Setup the star container to hold the star, the cell around it, etc
                var curStarContainer = SetupStarContainer(curStarPoint);
                StarContainers.Add(curStarPoint, curStarContainer.GetComponent <StarContainer>().Setup(curStarPoint, cell));
            });
        }
Esempio n. 2
0
 void SpawnCells(Delaunator delaunator, List <Vector3> cellCenters)
 {
     delaunator.ForEachVoronoiCell(dCell =>
     {
         var center            = cellCenters[dCell.Index];
         List <int> neighbours = GetNeighbours(dCell.Index).ToList();
         Cell cell             = new GameObject("Cell" + dCell.Index).AddComponent <Cell>();
         cell.Init(map, dCell, center, neighbours);
     });
 }
Esempio n. 3
0
        private void DrawVoronoi()
        {
            RefreshDelaunator();
            delaunator.ForEachVoronoiCell((cell) =>
            {
                var polygon = new Polygon
                {
                    Stroke          = VoronoiBrush,
                    StrokeThickness = .2,
                    Points          = new PointCollection(cell.Points.Select(point => new System.Windows.Point(point.X, point.Y)))
                };

                DrawCircles(cell.Points, VoronoiCircleBrush);
                PlayGround.Children.Add(polygon);
            });
        }