Skip to content

Instantly share code, notes, and snippets.

@nrrb
Last active November 30, 2019 06:49
Show Gist options
  • Save nrrb/bd2a012a87bc08c7021e8482ee925c18 to your computer and use it in GitHub Desktop.
Save nrrb/bd2a012a87bc08c7021e8482ee925c18 to your computer and use it in GitHub Desktop.
Using LaTeX to make circles on an equilateral triangle grid. Seed of Life Coloring Book.
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[left=0cm,top=2cm,right=0cm,bottom=0cm,nohead,nofoot]{geometry}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\r}{3}
% Given that A4 paper is 21cm x 29.7 cm, we can calculate the maximum number of circles that will fit on the page based on the radius
\pgfmathtruncatemacro{\xmax}{21/(\r*1.2)}
\pgfmathtruncatemacro{\ymax}{\xmax*sqrt(3)/2}
\foreach \x in {0,...,\xmax-1}
\foreach \y in {0,...,\ymax-1}
{
\pgfmathsetmacro{\xorigin}{\x*\r}
\pgfmathsetmacro{\yorigin}{\y*\r*sqrt(3)}
\pgfmathsetmacro{\xoffset}{\r*(\x+0.5)}
\pgfmathsetmacro{\yoffset}{(2*\y+1)*sqrt(3)*\r/2}
% Fading color depending on position!
% \pgfmathsetmacro{\c}{(\x+\y)/(\xmax+\ymax)}
% \definecolor{tracecolor}{rgb}{\c,\c,\c}
\draw[color=black] (\xorigin,\yorigin) circle [radius=\r cm];
\draw[color=black] (\xoffset, \yoffset) circle [radius=\r cm];
}
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment