I am passing an argument to a pic like so pic[n=3]. Am I doing it right? And how about passing several arguments, say two like so pic[n=3, r=1]?
I really like being able to write the argument explicitly inside square bracket, rather than say pic{3}{1} (difficult to remember the order of the arguments). I tried repeating what I did with \pgfkeysgetvalue{/tikz/n}\n for \r and adding .pic 2 args ={ or .pic n args = {2}{, but that failed.
\documentclass[class=article,border=2mm,tikz]{standalone}
\usetikzlibrary{calc}
\tikzset{%
circle pyramid/.pic ={
\begin{scope}
\pgfkeysgetvalue{/tikz/n}\n
\foreach \x in {\n,...,1} {
\draw[fill=white]
\ifnum\x=\n
(0,0)
\else
(row)++(60:2)
\fi
coordinate (row)%
\foreach \y in {1,...,\x} {
circle[radius=1]++(2,0)% circles of radius 1, would like to make it \r
};
}
\end{scope}
},
n/.initial=2
}
% radius of the circumscribed circle in terms of the smaller circle r
% R = r (3+2*(n-1)*sqrt(3))/3, and we set r = 1
\newcommand{\radius}[1]{\pgfmathparse{(3+2*(#1-1)*sqrt(3))/3}}%
\begin{document}
\begin{tikzpicture}
\radius{3}%
\draw[fill=black] circle[radius=\pgfmathresult cm];
\path (-2,-1.16) pic[n=3]{circle pyramid}; % inelegant tweak of the center
\end{tikzpicture}
\end{document}
The code for the pyramid of circles was borrowed from skillmon. I tried to reduce it to the minimum elements I needed. But as you can see from the screenshot, there is some unwanted white space on the right-hand side. I'd like to fix that too.


radius=\pgfmathresult cmis not the best way to pass a calculation to the argument, is there a better way? – PatrickT Apr 03 '21 at 13:05