private void BuildGrid() { var pointList = PoissonDisk.GeneratePoisson(ExampleUtils.ScreenRect, cellDimensions.magnitude, 10); grid = LineGrid <SpriteCell> .BeginShape().Segment(pointList.Count).EndShape(); var map2D = VoronoiMap <LinePoint> .MakeMap(pointList); voronoiMap = map2D.To3DXY(); foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = voronoiMap[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f; cell.name = point.ToString(); grid[point] = cell; } ExampleUtils.PaintScreenTexture(plane, voronoiMap.To2D(), ColorFunction); }
private void BuildGrid() { var pointList = PoissonDisk.GeneratePoisson(ExampleUtils.ScreenRect, cellDimensions.magnitude, 10); grid = LineGrid<SpriteCell>.BeginShape().Segment(pointList.Count).EndShape(); var map2D = VoronoiMap<LinePoint>.MakeMap(pointList); voronoiMap = map2D.To3DXY(); foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = voronoiMap[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f; cell.name = point.ToString(); grid[point] = cell; } ExampleUtils.PaintScreenTexture(plane, voronoiMap.To2D(), ColorFunction); }
private void BuildGrid() { //This is the base grid, we will use it to define //the shape of the splice grid. //The contents is not important. var baseGrid = PointyHexGrid <bool> .BeginShape() .Hexagon(5) .EndShape(); //This is the base map, used for the course //mapping var baseMap = new PointyHexMap(cellDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(baseGrid); //Now we make the actual spliced grid. //We feed it the base grid, and the number //of splices we want. grid = new SplicedGrid <SpriteCell, PointyHexPoint>(baseGrid, spliceOffsets.Length); //Now we make a spliced map. This is just a one-way map -- //it only maps grid points to the world (using the base map plus //splice point offsets var splicedMap = new SplicedMap <PointyHexPoint>(baseMap, spliceOffsets); //Finally, we make the above into a two way map. This map uses a Vonoroi diagram //to do the inverse mapping map = new VoronoiMap <SplicedPoint <PointyHexPoint> >(grid, splicedMap).To3DXY(); //Then we instantiate cells as usual, and put them in our grid. foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; //slightly lighter than the DefaultColors we will use to paint the background cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f; cell.name = point.ToString(); grid[point] = cell; } // To make it easier to see how points are mapped, we ExampleUtils.PaintScreenTexture(plane, map.To2D(), ColorFunction); }
private void BuildGrid() { //This is the base grid, we will use it to define //the shape of the splice grid. //The contents is not important. var baseGrid = PointyHexGrid<bool> .BeginShape() .Hexagon(5) .EndShape(); //This is the base map, used for the course //mapping var baseMap = new PointyHexMap(cellDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(baseGrid); //Now we make the actual spliced grid. //We feed it the base grid, and the number //of splices we want. grid = new SplicedGrid<SpriteCell, PointyHexPoint>(baseGrid, spliceOffsets.Length); //Now we make a spliced map. This is just a one-way map -- //it only maps grid points to the world (using the base map plus //splice point offsets var splicedMap = new SplicedMap<PointyHexPoint>(baseMap, spliceOffsets); //Finally, we make the above into a two way map. This map uses a Vonoroi diagram //to do the inverse mapping map = new VoronoiMap<SplicedPoint<PointyHexPoint>>(grid, splicedMap).To3DXY(); //Then we instantiate cells as usual, and put them in our grid. foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; //slightly lighter than the DefaultColors we will use to paint the background cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white*0.1f; cell.name = point.ToString(); grid[point] = cell; } // To make it easier to see how points are mapped, we ExampleUtils.PaintScreenTexture(plane, map.To2D(), ColorFunction); }