# Fill style that looks like hand-drawn / hand-filled with crayon

How to generate in LaTeX (TikZ or something similar) the following image:

This was not drawn by hand, as far as I known, but with some Mac tool.

-
tex.stackexchange.com/questions/39296/… might be a good starting spot for the hand drawn line aspect of it. –  Forkrul Assail Oct 17 '12 at 17:29
–  Jakub Narębski Oct 18 '12 at 11:52
@JakubNarębski: which ultimately comes from Create xkcd style diagram in TeX... –  Claudio Fiandrino Oct 18 '12 at 15:54

Here is a quick one: I've used the decoration that Forkrul Assail linked to and basically it's going back and forth between the corners just as you would do to hatch. However it's not really following the outer contour and you can make it more detailed if you define this as a genuine decoration following precisely the shape border. I didn't do it because I think Inkscape or something similar is much easier to perform this and I doubt that it is worth automating. Nevertheless the idea is essentially the same for the decoration anyhow.

Also much to my surprise the line join option is really showing a difference.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc,positioning,decorations}

\makeatletter
\pgfdeclaredecoration{penciline}{initial}{
\state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,auto corner on length=1mm,]{
\pgfpathcurveto%
{% From
\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}
{\pgfdecorationsegmentamplitude}
}
{%  Control 1
\pgfmathrand
{\pgfqpoint{-\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}%
{\pgfmathresult\pgfdecorationsegmentamplitude}
}
}
{%TO
}
}
\state{final}{}
}
\makeatother

\begin{document}
\begin{tikzpicture}[decoration={penciline,amplitude=2pt}]
\node[regular polygon,regular polygon sides=3,minimum height=2cm,draw] (a) {};
\node[below= 0.5cm of a] {\textsc{Working Copy}};
\draw[blue,opacity=0.3,decorate,line width=1mm,line join=round] (a.corner 3)
\foreach \x[remember=\x as \lastx(initially 0)] in {0.07,0.15,...,1.1}{
-- ($(a.corner 1)!\lastx!(a.corner 2)$) --($(a.corner 3)!\lastx+0.05!(a.corner 2)$)
}--(a.corner 2);

\node[cylinder, shape border rotate=90, aspect = 0.65,draw,
minimum height=1.7cm,minimum width=1.5cm] (b) at (4cm,0.2cm) {};
\node[below= 0.45cm of b] {\textsc{Copying Work}};
\draw[red,opacity=0.3,decorate,line width=0.9mm,line join=bevel] (b.after top)
\foreach \x[remember=\x as \lastx(initially 0)] in {0.1,0.2,...,1.1}{
-- ($(b.after top)!\lastx!(b.before bottom)$) --($(b.after top)!\lastx+0.05!(b.before top)$)
} --(b.before bottom)
\foreach \x[remember=\x as \lastx(initially 0)] in {0.1,0.2,...,1.1}{
-- ($(b.before bottom)!\lastx!(b.after bottom)$) -- ($(b.before top)!\lastx+0.05!(b.after bottom)$)
};
\end{tikzpicture}
\end{document}


-
This site restores my hope in humanity daily. Great work! –  Forkrul Assail Oct 18 '12 at 14:26
@ForkrulAssail Your comment is certainly among those nice things that you see on this site, thank you! –  percusse Oct 18 '12 at 19:25

I think for this one idea should be create a custom pattern, but my solution is far from being good. Indeed I remember having read somewhere that paths are evils and today I discover why: bit modifications of the parameters lead to very different outputs. To have something a bit stable, one could set the seed by means of:

\pgfmathsetseed{<some value>}


As starting point I used custom and built in tikz fill patterns.

The code:

\documentclass{article}
% for the font
\renewcommand*\sfdefault{augie}
\renewcommand*\familydefault{\sfdefault}
\usepackage{tikz}
\usetikzlibrary{positioning,patterns,shapes.geometric}

% defining the new dimensions
\newlength{\hatchthickness}
% declaring the keys in tikz
hatchthickness/.code={\setlength{\hatchthickness}{#1}}}
% setting the default values
hatchthickness=0.4pt}
% declaring the pattern
{custom north west lines}% name
{\pgfqpoint{-2\hatchthickness}{-2\hatchthickness}}% lower left corner
{% shape description
\pgfsetlinewidth{\hatchthickness*rand}
\pgfpathcurveto
\pgfsetstrokeopacity{0.175}
\pgfsetstrokecolor{blue}
\pgfusepath{stroke}
}

\begin{document}
\pgfmathsetseed{123564} % to have always the same result
\begin{tikzpicture}
\node[draw,cylinder,scale=8,rotate=90,aspect=0.25, pattern= custom north west lines, ,hatchspread=6.2pt,hatchthickness=17pt] at (0,-3){};
\node at (0,-4.5) {\textsc{Repository}};

\node[draw,regular polygon,regular polygon sides=3, scale=4.25, yshift=-0.02cm,
pattern= custom north west lines, ,hatchspread=6.2pt,hatchthickness=17pt] at (5,-3){};
\node at (5,-4.5) {\textsc{Working Copy}};

\end{tikzpicture}%

\end{document}


and the result is:

BTW: If one needs to fill something with almost roof tiles, here's a code to do that:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing,patterns,shapes.geometric}

% To draw tiles
% defining the new dimensions
\newlength{\hatchthickness}
% declaring the keys in tikz
hatchthickness/.code=\setlength{\hatchthickness}{#1},
% declaring the pattern
{custom north west lines}% name
{\pgfqpoint{-2\hatchthickness}{-2\hatchthickness}}% lower left corner
{% shape description
\pgfsetlinewidth{\hatchthickness*rand}
\pgfpathcurveto
\pgfsetstrokeopacity{0.5}
\pgfusepath{stroke}
}

\begin{document}
\pgfmathsetseed{123561} % to have always the same result
\begin{tikzpicture}
\node[draw,trapezium,scale=9, pattern= custom north west lines,hatchspread=6pt,hatchthickness=9pt] (s) at (0,-3){};
\end{tikzpicture}%
\end{document}


The output:

Just for fun (and for fans of hand drawns):

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,decorations,decorations.pathmorphing,patterns,shapes.geometric}

\makeatletter
\pgfdeclaredecoration{penciline}{initial}{
\state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,auto corner on length=1mm,]{
\pgfpathcurveto%
{% From
\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}
{\pgfdecorationsegmentamplitude}
}
{%  Control 1
\pgfmathrand
{\pgfqpoint{-\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}%
{\pgfmathresult\pgfdecorationsegmentamplitude}
}
}
{%TO
}
}
\state{final}{}
}
\makeatother

% To draw tiles
% defining the new dimensions
\newlength{\hatchthickness}
% declaring the keys in tikz
hatchthickness/.code=\setlength{\hatchthickness}{#1},
% declaring the pattern
{custom north west lines}% name
{\pgfqpoint{-2\hatchthickness}{-2\hatchthickness}}% lower left corner
{% shape description
\pgfsetlinewidth{\hatchthickness*rand}
\pgfpathcurveto
\pgfsetstrokeopacity{0.5}
\pgfusepath{stroke}
}

\tikzset{window/.style={
draw, fill=cyan!20,
rectangle, minimum size=8bp,
decorate, decoration=penciline,
append after command={
[shorten >=1.5\pgflinewidth, shorten <=1.5\pgflinewidth,]
(\tikzlastnode.north) edge[decorate, decoration=penciline] (\tikzlastnode.south)
(\tikzlastnode.east) edge[decorate, decoration=penciline] (\tikzlastnode.west)
}
}
}

\begin{document}
\pgfmathsetseed{123561}
\begin{tikzpicture}
\node[draw,trapezium,scale=5,
decorate, decoration=penciline,
pattern= custom north west lines,
preaction={fill=red!80!black!50}] (s) at (0,0){};

\begin{scope}[on background layer]
\draw[decorate,decoration=penciline,fill=yellow!15] ($(s.bottom left corner)!0.3!(s.south west)$)--++(0,-1.5)--++(2.2,0)--    ($(s.bottom right corner)!0.3!(s.south east)$);
\end{scope}

\draw[decorate,decoration=penciline,fill=brown!50] ([yshift=-1.5cm]$(s.bottom side)!0.3!(s.south west)$)--++(0,0.65)--++(0.4,0)--    ([yshift=-1.4cm]$(s.bottom side)!0.3!(s.south east)$);
\draw[fill=brown] ([yshift=-1.2cm]$(s.bottom side)!0.2!(s.south east)$) circle(1bp);

\node[window,yshift=-0.5cm] at (s.south west) {};
\node[window,yshift=-0.5cm] at (s.south east) {};

\end{tikzpicture}%
\end{document}

-
they are too regular, but still they're nice :) –  tohecz Oct 19 '12 at 15:30
Thanks. :) When I started I thought was possible to make patterns a bit more random, but after some trials I recognize that it's not so obvious.. anyway I really like this roof tiles :D –  Claudio Fiandrino Oct 19 '12 at 15:36
Haha! I've just seen the house. Instant classic. –  percusse Oct 19 '12 at 18:42
@percusse: If answers had tags, mine should go under {fun} :D. –  Claudio Fiandrino Oct 20 '12 at 9:23
very nice!! =D The application that you found for this feature is very cool. –  tecepe Oct 20 '12 at 14:03