Walk around a coordinate in circular order to a distance of N
You can do this in a stateless manner.

Here is python code that generates the infinite walk:

def circular():
    yield (0,0)
    x,y = -1,0
    while True:
        yield (x,y)
        if x &lt; 0 and 0 &lt;= y &lt; -x:
            y += 1
        elif y &gt; 0 and x &lt; y:
            x += 1
        elif x &gt; 0 and y &gt; -x:
            y -= 1
        elif y &lt; 0 and x &gt; y:
            x -= 1
        elif x &lt; 0 and y &lt; -1:
            y += 1
        elif x &lt; 0 and y == -1:
            x -= 1
            y += 1