How can I calculate the formula of this fractal-like structure? I did the following fractal-like structure manually, and I was trying to convert it to a formula (or an algorithm including formulas) to compute some parts of the drawing, but I get lost due to the complexity of the structure. Is as follows:

Basically is the sequence of natural numbers represented by bars of the length of the natural number, growing up around the center which is the number $1$. It rotates clock-wise (Right,Down,Left,Up) and the next bar starts (is located) in the closest free point to $1$ in the corresponding rotating side that is touching a bar of the previous rotating side. The distance of the numbers represented by adjacent bars of the same side (except in the case of the numbers surrounding $n=1$) is always $d=4$.

I would like to obtain for each $n$ the values of those $k$ located in the next rotating side (clock-wise) touching perpendicularly the side of $n$.

E.g.: looking at the orange color, the vertical bar is $n=6$, but there are only four perpendicular bars from the next rotating side touching the side of $n=6$. They are $k=7,11,15,19$. Another example in blue, $n=8$ is touched only by $k=17,21,25,29$ in the next rotating side. As it can be seen in the image, depending on the number, and due to the construction of the structure, sometimes there are four numbers, sometimes only three touching the corresponding $n$. The numbers around $n=1$ are special cases.
(Update: extended graph, 2015/07/06)
So far I have been able to prepare manually a basic graph to try to understand the relations (still working on it, just a sample of how it works):


If somebody could give me a hint or idea about how to calculate those next $k$'s touching each $n$ would be very appreciated. Indeed probably this fractal is already available somewhere because the idea is quite simple, if somebody knows of some place with information please let me know. Thank you!

 A: In each of the four "staircases" we have the pattern $4 4 4 3$ of length $15$ repeating periodically, but the different staircases have different phases, resulting from the "havoc" at the center. The complete spiral pattern repeats under $k\rightsquigarrow k+60$.
In the following figure the rectangles have been replaced by segments connecting the centers of the constituent squares. The staircases are shown in green.

A function $f:{\mathbb Z}\to{\mathbb Z}$ producing a staircase of the desired kind can be obtained as follows: Such an $f$ has a linear part increasing $4$ units every $15$ steps and a periodic part of period $15$. We choose the origin such that $f(-2)=-1$, $f(-1)=f(0)=f(1)=0$, $f(2)=1$. Then
$$f(x)= {4\over15}x +q\bigl({\rm mod}_{15}(x)\bigr)\ ,$$
whereby the function $q$ is odd and has the following values:
$$q(0)=0,\quad q(\pm1)=\mp{4\over15},\quad q(\pm2)=\pm{7\over15},\quad\ldots$$
For implementing purposes it might be simplest to tabulate these values once and for all. But there is also an analytical expression for $q(\cdot)$ in the form
$$q(x)=\sum_{k=1}^7 b_k\sin{2\pi k x\over15}\ .$$
One obtains the following numerical values for the $b_k$:
$$\eqalign{& b_1=  0.0897088,\quad b_2= 0.0670339, \quad b_3= 0.11342, \quad
  b_4= -0.320649, \cr & b_5= -0.07698, \quad b_6= -0.0700975, \quad 
  b_7= -0.163906\ .\cr}$$
  The following figure shows the resulting $f$, whereby the obtained values for $q$ were rounded to the nearest integer.

Now to the main figure! I let $k$ denote the length of the segment to be drawn, and $k=0$ is the origin.
  Given $k$, the remainder $v:={\rm mod}_4(k)$ determines the direction of the segment. Assume that $v=1$. Then the segment is directed southward and has a constant $x$-coordinate given by $x={k-v\over4}+1$. It remains to determine the $y$-coordinate of the starting point. Looking at the main figure we see that  $x=14$ corresponds to $x=0$ in the definition of $f$. It follows that $y=f(x+1)+c$ whereby this $c$  is the same for all $k$ with $v=1$. It turns out that in fact
  $$y=f(x+1)-1\qquad(k\geq1)\ .$$
  I leave the discussion of the other three values of $v$ to you.
