I am attempting to draw a squiggly circle in order to delineate an area of a figure, but in a manner that emphasizes the arbitrariness of the precise boundary - something like the circle below, but more distorted and random. I cannot figure out a good way of approaching this with TikZ - any suggestions?
-
The closest earlier post I could find is tex.stackexchange.com/q/508410/194703.– user194703Mar 3, 2020 at 16:07
-
These solutions work great, thanks - I must have been searching with the wrong terms.– Henry ShackletonMar 3, 2020 at 18:34
1 Answer
How about
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={rr=1+0.1*rnd;}]
\draw plot[smooth cycle,variable=\t,samples at={0,45,...,315}] (\t:2*rr);
\end{tikzpicture}
\end{document}
You can make it a pic, and thus make the "randomness" parameters like amplitude or the number of samples.
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/random circle/.style={code={
\tikzset{random circle/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/random circle/##1}}%
\pgfmathsetmacro{\nextt}{360/\pv{samples}}
\pgfmathsetmacro{\lastt}{360-\nextt}
\draw plot[smooth cycle,variable=\t,samples at={0,\nextt,...,\lastt}]
(\t:\pv{radius}+rnd*\pv{amplitude});
}},random circle/.cd,radius/.initial=1,amplitude/.initial=0.1,
samples/.initial=8]
\path (0,0) pic{random circle}
(4,0) pic[blue]{random circle={radius=2,amplitude=0.3,samples=12}}
(0,-4) pic[red]{random circle={radius=2,amplitude=0.5,samples=16}};
\end{tikzpicture}
\end{document}
-
How would I make the "squiggly circles" thicker. I tried adding
thick
, and evenvery thick
, as in:\draw plot[very thick,smooth cycle,variable=\t,samples at={0,\nextt,...,\lastt}]
.... However, this seems to have no effect.– murrayMar 3, 2020 at 17:29 -
@murray You add
very thick
to the options ofplot
. However, you need\draw[very thick] plot[smooth cycle,variable=\t,samples at={0,\nextt,...,\lastt}] ...
. Yet, if you use the pic, you only needpic[very thick]{random circle}
.– user194703Mar 3, 2020 at 17:31