I'm trying to understand the code in an answer regarding drawing closed paths so that I might be able to manipulate it further. Here is a small portion of it:
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
% decorating every segment of a path
% https://tex.stackexchange.com/a/69225
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}
\newcommand\irregularcircle[2]{% radius, irregularity
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
+(0:\len pt)
\foreach \a in {10,20,...,350}{
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
-- +(\a:\len pt)
} -- cycle
}
\begin{document}
\begin{tikzpicture}
% Set the seed for the random function to a fixed value to get
% the same picture at every run
\pgfmathsetseed{12345}
\coordinate (c) at (0,0);
\draw[blue,rounded corners=1mm] (c) \irregularcircle{3cm}{1.5mm};
\draw[red,rounded corners=1mm] (c) \irregularcircle{1cm}{1.5mm};
\end{tikzpicture}
\end{document}
I get stuck with understanding the following macro:
\newcommand\irregularcircle[2]{% radius, irregularity
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
+(0:\len pt)
\foreach \a in {10,20,...,350}{
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
-- +(\a:\len pt)
} -- cycle
}
This Tikz-pfg manual says that
... this operation (
\pgfextra) should only be used by real experts and should only be used deep inside clever macros, not on normal paths.
Would anybody explain how each line in the definition of the macro \irregularcircle works?

\pgfextra, then why not say so? – cfr Mar 23 '17 at 01:58\tikzsetpart. – Symbol 1 Mar 23 '17 at 02:48irregularcircle, not all the lines in the code mentioned in the beginning. My question is indeed mainly about\pgfextra. I don't understand the part+(0:\len pt)either. I should have made the question clearer. – Mar 23 '17 at 12:26