[Tex/LaTex] How to draw the following special table in tikz

tikz-pgf

I don't know How to draw the following special table in tikz?
I know some elementary commands of tikz but I am confused! Any suggest are appreciate.

UPDATE: WME:

    \documentclass{article}
    \usepackage{tikz}

    \begin{document}
    \begin{tikzpicture}
    \draw (0,0)--(0,10)--(10,10)--(10,0)--(0,0);
    \draw (0,1)--(10,1);
    \draw (0,2)--(10,2);
    \draw (0,3)--(10,3);
    \draw (0,4)--(10,4);
    \draw (0,5)--(10,5);
    \draw (0,6)--(10,6);
    \draw (0,7)--(10,7);
    \draw (0,8)--(10,8);
    \draw (0,9)--(10,9);
    %---------------------
    \draw (1,0)--(1,10);
    \draw (2,0)--(2,10);
    \draw (3,0)--(3,10);
    \draw (4,0)--(4,10);
    \draw (5,0)--(5,10);
    \draw (6,0)--(6,10);
    \draw (7,0)--(7,10);
    \draw (8,0)--(8,10);
    \draw (9,0)--(9,10);
    %------------------------

    \draw[very thick](0,10)--(10,10)--(10,0)--(0,0)--(0,9)-- (9,9)--(9,1)--        (1,1)--(1,8)--(8,8)--(2,8)--(8,8)--(8,2)--(2,2)--(2,7)--(7,7)--(7,3)--(3,3)--(3,6)   --(6,6)--(6,4)--(4,4)--(4,5)   --(5,5);
    \end{tikzpicture}
    \end{document}

enter image description here

Best Answer

My solution uses the spiral code which I translated to lua with some modification.

\documentclass{article}

\usepackage{luacode}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1]
  \draw[step=1,very thin,xshift=0.5cm,yshift=0.5cm] (-5,-5) grid (5,5);

  % position numbers
  \begin{luacode}
    function isPrime(n)
      primes = {}
      if n <= 0 then
        return false
      end
      if n <= 2 then
        return true
      end
      if n % 2 == 0 then
        return false
      end
      for i = 3,n/2,2 do
        if n % i == 0 then
          return false
        end
      end
      return true
    end

    NUM = 100
    di = 1
    dj = 0
    i = 0
    j = 0
    segment_passed = 0
    segment_length = 1
    for k=0, (NUM-1) do
      if isPrime(k+1) then
        tex.sprint("\\draw ("..(i-0.5)..","..(j-0.5)..") -- ("..(i+0.5)..","..(j+0.5)..");")
        tex.sprint("\\draw ("..(i-0.5)..","..(j+0.5)..") -- ("..(i+0.5)..","..(j-0.5)..");")
        tex.sprint("\\draw node at ("..i..","..j..") {\\colorbox{white}{"..(k+1).."}};")
      else
        tex.sprint("\\draw node at ("..i..","..j..") {"..(k+1).."};")
      end
      i = i + di
      j = j + dj
      segment_passed = segment_passed + 1

      if segment_passed == segment_length then
        segment_passed = 0
        tmp = di
        di = -dj
        dj = tmp
        if dj == 0 then
          segment_length = segment_length + 1
        end
      end
    end
  \end{luacode}

  % draw spiral
  \begin{luacode}
    NUM = 120
    di = -1
    dj = 0
    i = 0
    j = 0
    segment_passed = 0
    segment_length = 1
    for k=0, (NUM-1) do
      tex.sprint("\\draw[ultra thick,line cap=round] ("..(i+0.5)..","..(j+0.5)..") -- ")
      i = i + di
      j = j + dj
      tex.sprint("("..(i+0.5)..","..(j+0.5)..");")
      segment_passed = segment_passed + 1

      if segment_passed == segment_length then
        segment_passed = 0
        tmp = di
        di = -dj
        dj = tmp
        if dj == 0 then
          segment_length = segment_length + 1
        end
      end
    end
  \end{luacode}

\end{tikzpicture}

\end{document}

enter image description here

Update I figured out that the sketch may belong to the Ulam spiral. Thus, the diagonal lines in case of some prime numbers should indicate the diagonal lines within such a spiral.

Just for fun, I adapted my example code to generate the figure similar to the Wikipedia article. (I'll hope it is not too much off topic)

\documentclass{article}

\usepackage{luacode}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=0.05]
  % position circles
  \begin{luacode}
    function isPrime(n)
      primes = {}
      if n <= 0 then
        return false
      end
      if n <= 2 then
        return true
      end
      if n % 2 == 0 then
        return false
      end
      for i = 3,n/2,2 do
        if n % i == 0 then
          return false
        end
      end
      return true
    end

    NUM = 40000
    di = 1
    dj = 0
    i = 0
    j = 0
    segment_passed = 0
    segment_length = 1
    for k=0, (NUM-1) do
      if isPrime(k+1) then
        tex.sprint("\\filldraw ("..i..","..j..") circle (0.3);")
      else
        -- tex.sprint("\\draw node at ("..i..","..j..") {"..(k+1).."};")
      end
      i = i + di
      j = j + dj
      segment_passed = segment_passed + 1

      if segment_passed == segment_length then
        segment_passed = 0
        tmp = di
        di = -dj
        dj = tmp
        if dj == 0 then
          segment_length = segment_length + 1
        end
      end
    end
  \end{luacode}

\end{tikzpicture}

\end{document}

enter image description here

Related Question