1

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?

enter image description here

| improve this question | | | | |
6

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}

enter image description here

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}

enter image description here

| improve this answer | | | | |
  • How would I make the "squiggly circles" thicker. I tried adding thick, and even very thick, as in: \draw plot[very thick,smooth cycle,variable=\t,samples at={0,\nextt,...,\lastt}] .... However, this seems to have no effect. – murray Mar 3 at 17:29
  • @murray You add very thick to the options of plot. However, you need \draw[very thick] plot[smooth cycle,variable=\t,samples at={0,\nextt,...,\lastt}] .... Yet, if you use the pic, you only need pic[very thick]{random circle}. – Schrödinger's cat Mar 3 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.