I created a hexagonal spiral, but ran into a problem while trying to number it. The spiral is created in 2 sections. I can manually number the whole thing, as I did below, but I haven't been able to find an easier method.
I read about a way to number a spiral, iterating through the rings, but it didn't seem to work very well with how TeX generates the shapes. Here is that method:
function cube_spiral(center, radius):
var results = [center]
for each 1 ≤ k ≤ radius:
results = results + cube_ring(center, k)
return results
My hexagonal grid is a variant of this grid.
What is should look like:
Code to generate the hexagonal spiral (with partial manual numbering):
\documentclass{standalone}
\usepackage{tikz}
\usepackage{ifthen} % if else statements
\usetikzlibrary{shapes} %allows hexagons
\begin{document}
\begin{tikzpicture} [hexa/.style= {shape=regular polygon, regular polygon sides=6, minimum size=1cm, draw, inner sep=0, anchor=south, fill=darkgray!85!white, rotate=0},numbr/.style= {white},arro/.style= {draw,red,thick}]
\pgfmathsetmacro\radius{4}
\pgfmathsetmacro\diameter{\radius*2}
\pgfmathsetmacro\shortdiameter{\radius*2-1}
\pgfmathsetmacro\largeradius{\radius+1}
\pgfmathsetmacro\shortradius{\radius-1}
% base hexagon (created in 2 sections and rotated 90 degrees)
\begin{scope}[rotate=90]
\foreach \j in {0,...,\radius}{%
\pgfmathsetmacro\end{\radius+\j}
\foreach \i in {0,...,\end}{%
\node[hexa] (h\i;\j) at ({(\i-\j/2)*sin(60)},{\j*0.75}) {}; %{\i;\j};
}
}
\foreach \j in {0,...,\shortradius}{%
\pgfmathsetmacro\end{\shortdiameter-\j}
\foreach \i in {0,...,\end}{%
\node[hexa] (h\i;\j) at ({(\i+\j/2-\shortradius*0.5)*sin(60)},{\j*0.75+\radius*0.75+0.75}) {}; %{\i;\j};
}
}
% color change(s)
\node[hexa, fill=blue!20!white] (h\radius;\radius) at ({(\radius-\radius/2)*sin(60)},{\radius*0.75}) {};
% manual numbering
\node (h4;4) at ({(4-4/2+0.5)*sin(60)},{4*0.75}) {0};
\node[numbr] (h4;3) at ({(4-3/2+0.5)*sin(60)},{3*0.75}) {1};
\node[numbr] (h3;3) at ({(3-3/2+0.5)*sin(60)},{3*0.75}) {2};
\node[numbr] (h3;4) at ({(3-4/2+0.5)*sin(60)},{4*0.75}) {3};
\node[numbr] (h3;0) at ({(3+0/2-\shortradius*0.5+0.5)*sin(60)},{0*0.75+\radius*0.75+0.75}) {4};
\node[numbr] (h4;0) at ({(4+0/2-\shortradius*0.5+0.5)*sin(60)},{0*0.75+\radius*0.75+0.75}) {5};
\node[numbr] (h5;4) at ({(5-4/2+0.5)*sin(60)},{4*0.75}) {6};
\node[numbr] (h5;3) at ({(5-3/2+0.5)*sin(60)},{3*0.75}) {7};
% ... etc ...
% special shape(s)
\pgfmathsetmacro\arrowlen{0.2}
\foreach \i in {4,...,7}{%
\draw[arro, ->, to path={-- (\tikztotarget)}]
({(\i-4/2+0.5)*sin(60)+\arrowlen/2},{4*0.75-\arrowlen}) to ({(\i-3/2+0.5)*sin(60)-\arrowlen/2},{3*0.75+\arrowlen});
}
\end{scope}
\end{tikzpicture}
\end{document}