4

Reading this question : Simulating hand-drawn lines and following Percusse's idea I tried this :

enter image description here enter image description here

But is it possible to "hide" the multido code in a style command and pass the parameters throu keys. By the way, for a step of 0.01, there is 101 marks but for a step of 0.2 there is only 50, and the line doesn't go to the end ?

\documentclass[tikz]{standalone}
\usepackage{}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}[decoration={markings,
mark=between positions 0 and 1 step .01 with {
\node at (0,.3pt*rand) [coordinate,
name=mark-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}]
{};}}]
\draw [help lines] grid (3,2);
\draw [postaction={decorate},help lines] (0,0) -- (3,1) arc (0:180:1.5 and 1);
\draw[smooth] [red] (mark-1)
    \foreach \i in {2,...,101} {-- (mark-\i) } ;
\end{tikzpicture}

\begin{tikzpicture}[decoration={markings,
mark=between positions 0 and 1 step .01 with {
\node at (0,.4pt*rand) [coordinate,
name=mark-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}]
{};}}]
\draw [help lines] grid (3,2);
\path [postaction={decorate}] (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle ;
\draw[smooth,red,fill=red!15] (mark-1)
    \foreach \i in {2,...,101} {-- (mark-\i) } ;
\end{tikzpicture}

\end{document}
3

Here is a way to do what you request. Probably not the best.

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{%
  hand drawn/random interval/.initial = 1pt,
  hand drawn/step/.initial = 0.05,
  hand drawn with markings/.style = {%
   decoration={%
    markings,
    mark = between positions 0 and 1 step \pgfkeysvalueof{/tikz/hand drawn/step} with {%
      \edef\SequenceNumber{%
        \pgfkeysvalueof{/pgf/decoration/mark info/sequence number}}%
      \coordinate (mark-\SequenceNumber) at
      (0,\pgfkeysvalueof{/tikz/hand drawn/random interval}*rand);
      \ifnum\SequenceNumber>1\relax
      \draw[#1] (mark-\number\numexpr\SequenceNumber-1\relax) 
        -- 
        (mark-\SequenceNumber);
      \fi},
    },
    decorate},
}
\begin{document}

\begin{tikzpicture}
  \draw [help lines] grid (3,2);
  \draw [hand drawn with markings = {red}] (0,0) -- (3,1) arc (0:180:1.5 and 1);
\end{tikzpicture}

\end{document}
  • Thank you for this answer, but I just realized that you can not make a cycle and fill it with this methode. – Tarass May 19 '14 at 5:43
  • \usetikzlibrary{decorations.pathmorphing} with random steps does it as well. I've missed it. – Tarass May 19 '14 at 7:18

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.