Example #1
0
        static public void Line(Grid2DInt grid, Vector2Int p1, Vector2Int p2, int width = 0, int data = 255)
        {
            Diamond(grid, p1.x, p1.y, width, data);
            Diamond(grid, p2.x, p2.y, width, data);

            Vector2 dif = new Vector2(p2.x - p1.x, p2.y - p1.y);

            int xLength = Math.Abs(p2.x - p1.x);

            for (int i = 0; i < xLength; i++)
            {
                for (int w = -width; w <= width; w++)
                {
                    grid[p1.x + (int)(i * dif.x / xLength), p1.y + (int)(i * dif.y / xLength) + w] = data;
                }
            }

            int yLength = Math.Abs(p2.y - p1.y);

            for (int i = 0; i < yLength; i++)
            {
                for (int w = -width; w <= width; w++)
                {
                    grid[p1.x + (int)(i * dif.x / yLength) + w, p1.y + (int)(i * dif.y / yLength)] = data;
                }
            }
        }
Example #2
0
        void Flow(Grid2DInt grid, int length)
        {
            if (lastEdges.Count <= 0)
            {
                return;
            }
            foreach (var point in lastEdges)
            {
                flowGrid[point] = length;
            }
            length++;
            maxLength = Math.Max(length, maxLength);
            List <Vector2Int> tmpPoints = new List <Vector2Int>();

            foreach (var point in lastEdges)
            {
                foreach (var p in Grid2DInt.ortho)
                {
                    var pp = point + p;
                    if (Contain(pp, tmpPoints))
                    {
                        continue;
                    }
                    if ((grid[pp] != 255) || (flowGrid[pp] != 0))
                    {
                        continue;
                    }
                    tmpPoints.Add(pp);
                }
            }
            lastEdges = tmpPoints;
            Flow(grid, length);
        }
Example #3
0
 public Grid2DInt Fill(Grid2DInt grid, Vector2Int point)
 {
     flowGrid  = new Grid2DInt(grid.Width, grid.Height);
     maxLength = 0;
     lastEdges.Clear();
     lastEdges.Add(point);
     Flow(grid, 0);
     return(flowGrid);
 }
Example #4
0
 static public void Square(Grid2DInt grid, int x, int y, int size = 3, int data = 255)
 {
     for (int row = -size; row < size + 1; row++)
     {
         for (int col = -size; col < size + 1; col++)
         {
             grid[x + col, y + row] = data;
         }
     }
 }
Example #5
0
 static public void Diamond(Grid2DInt grid, int x, int y, int size = 3, int data = 255)
 {
     for (int row = -size; row < size + 1; row++)
     {
         for (int col = -size; col < size + 1; col++)
         {
             int dis = Math.Abs(row) + Math.Abs(col);
             if (dis <= size)
             {
                 grid[x + col, y + row] = data;
             }
         }
     }
 }
Example #6
0
        public Vector2Int Step(Grid2DInt grid)
        {
            Vector2Int nextPos;

            do
            {
                nextPos = curPos + moveTable[Random.Range(0, moveTable.Count)];
            } while(!grid.Inside(nextPos.x, nextPos.y));
            curPos = nextPos;
            //nextPos = curPos + moveTable[Random.Range(0, moveTable.Count)];
            //if(grid.Inside(nextPos.x, nextPos.y)) {
            //    curPos = nextPos;
            //}
            return(curPos);
        }
Example #7
0
 public void Count(Grid2DInt grid, int value)
 {
     CountMap = new Grid2DInt(grid.Width, grid.Height);
     MaxCount = 0;
     for (int y = 0; y < grid.Height; y++)
     {
         for (int x = 0; x < grid.Width; x++)
         {
             if (grid[x, y] != 255)
             {
                 continue;
             }
             var cnt = grid.CountRect(new UnityEngine.Vector2Int(x, y), 2, 0);
             MaxCount       = Math.Max(MaxCount, cnt);
             CountMap[x, y] = cnt;
         }
     }
 }