I need to generate grid shells for a given level. For example, the 2d grid "shell" at level 0 is just the cell (0,0). The level 1 shell would be every cell surrounding (0,0), the level 2 shell surrounds that one, etc.
The formula for the number of shells at each level is 8*level for each level above 0, and 1 cell for level 0.
The formula for the total number of shells is just the (number of side cells + 1) / 2
So, the output for level 1 would be the coordinates (in no particular order)
(-1,0)
(0,-1)
(1, 0)
(0, 1)
(1, 1)
(-1, 1)
(1, -1)
(-1,-1)
I'm struggling to come up with an algorithm to generate the coordinates at each level, despite knowing how many there should be, and what the coordinates are for each given level.
It would be even better if the coordinates for a given shell were ordered by distance from (0,0)
I'm also interested in how this would scale to 3d.