Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    private void BuildGrid()
    {
        grid = LineGrid <SpriteCell>
               .BeginShape()
               .Segment(300)
               .EndShape();

        map2D = new ArchimedeanSpiralMap(CellDimensions, grid)
                .AnchorCellMiddleCenter()
                .WithWindow(ExampleUtils.ScreenRect)
                .AlignMiddleCenter(grid);

        map = map2D
              .To3DXY();

        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;

            cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.2f;
            cell.name  = point.ToString();

            grid[point] = cell;
        }

        voronoiMap = new VoronoiMap <LinePoint>(grid, map2D);
        ExampleUtils.PaintScreenTexture(plane, voronoiMap, ColorFunction);
    }
Ejemplo n.º 3
0
    public void Start()
    {
        var grid = LineGrid <int>
                   .BeginShape()
                   .Segment(10)
                   .EndShape();

        var map = new ArchimedeanSpiralMap(CellDimensions, grid);

        var voronoiMap = new VoronoiMap <LinePoint>(grid, map);

        ExampleUtils.PaintScreenTexture(plane, voronoiMap, n => Mathi.Mod(n, 12));
    }
Ejemplo n.º 4
0
    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(3)
                       .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);
    }