Say I wanted to define a function in TiKz for drawing an eye:
\begin{tikzpicture}
%eye
\pgfmathsetmacro{\eyeSize}{1}
\pgfmathsetmacro{\ex}{0}
\pgfmathsetmacro{\ey}{1}
\pgfmathsetmacro{\eRot}{-10}
\pgfmathsetmacro{\eAp}{-55}
\draw[rotate around={\eRot:(\ex,\ey)}] (\ex,\ey) -- ++(-.5*\eAp:\eyeSize)
(\ex,\ey) -- ++(.5*\eAp:\eyeSize);
\draw (\ex,\ey) ++(\eRot+\eAp:.75*\eyeSize) arc (\eRot+\eAp:\eRot-\eAp:.75*\eyeSize);
% IRIS
\draw[fill=gray] (\ex,\ey) ++(\eRot+\eAp/3:.75*\eyeSize) % start point
arc (\eRot+180-\eAp:\eRot+180+\eAp:.28*\eyeSize);
%PUPIL, a filled arc
\draw[fill=black] (\ex,\ey) ++(\eRot+\eAp/3:.75*\eyeSize) % start point
arc (\eRot+\eAp/3:\eRot-\eAp/3:.75*\eyeSize);
\end{tikzpicture}
This is too long! How would I define a "function" in TiKz, so that I can call something \eye( \ex, \ey, \rotation, \eyeAperture ) to produce an eye?

#1,#2etc? – bobobobo Aug 10 '12 at 18:48pgfkeysofxkeyval. There you predefine keys (and probably default values), then you can use specify them by e.g.\eye[radius=4,x=2,y=3,rotation=135]– Tom Bombadil Aug 10 '12 at 19:29\pgfmathsetmacro{\radius}{#1}. That way you can use\radiusinstead of#1, the readability would definitively improve. – Tom Bombadil Aug 24 '12 at 00:14% IRIS \draw[fill=gray] (#2,#3) ++(#4+55/3:.75*#1) arc (#4+180-55:#4+180+55:.28*#1); \draw[fill=gray] (#2,#3) ++(#4+55/3:.75*#1) arc (#4+55/3:#4-55/3:.75*#1); %PUPIL, a filled arc \draw[fill=black] (#2,#3) ++(#4+20/3:.75*#1) arc (#4+180-75:#4+180+75:.085*#1);– skvery Apr 19 '20 at 20:55