# Generate coloured fancy Delaunay patterns in Tikz

Recently in the world of the Internet this very fancy coloured pattern appeared:

I was thinking if it is possible to generate something similar with TikZ. I saw this first example here in Drawing unstructured grids with Tikz

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i [evaluate={\ii=int(\i-1);}] in {0,...,7}{
\foreach \j [evaluate={\jj=int(\j-1);}] in {0,...,7}{
\coordinate [shift={(\j,\i)}] (n-\i-\j) at (rand*180:1/4+rnd/8);
\ifnum\i>0
\draw [help lines] (n-\i-\j) -- (n-\ii-\j);
\fi
\ifnum\j>0
\draw [help lines] (n-\i-\j) -- (n-\i-\jj);
\ifnum\i>0
\pgfmathparse{int(rnd>.5)}
\ifnum\pgfmathresult=0
\draw [help lines] (n-\i-\j) -- (n-\ii-\jj);
\else%
\draw [help lines] (n-\ii-\j) -- (n-\i-\jj);
\fi%
\fi
\fi
}}
\end{tikzpicture}
\end{document}


That produces this pattern:

The big problem here is to add some random coloring with light shading. Is there some way in TikZ to specify gradients inside area defined by nodes?

• They are triangles with solid/shaded colors so yes it is possible. – percusse Jun 15 '16 at 16:15
• Why are you asking? Just curiosity or do you want to do it? If so, what have you tried? Very nearly almost all questions should include a Minimal Working Example or a Minimal Non-Working Example (if Not Working is the problem the question asks about). We have a number of procrastinators. Eventually, one of them will probably answer this if anybody knows what a Delaunay tesselation is when it's at home. I think they ought not answer. I also think I ought not answer such questions but sometimes yield to temptation anyway. Luckily, I'm off the hook this time as I've no idea where Delaunay lives. – cfr Jun 16 '16 at 0:42
• I've just added an idea on how to produce a Delaunay tesselation of random geometric 2D points, the problem is how to produce a nice shading. – linello Jun 16 '16 at 8:39
• A lot of shoulds again... – percusse Jun 16 '16 at 11:19

You could shade it if you make the paths closed.

This is based on Mark Wibrow's code, as quoted in the question.

% answer to https://tex.stackexchange.com/questions/314918/generate-coloured-fancy-delaunay-patterns-in-tikz, modifying code by Mark Wibrow at https://tex.stackexchange.com/a/260652/
\documentclass[tikz,border=10pt,multi,rgb]{standalone}
% xcolor manual: 34
\resetcolorseries[12]{colours}
\tikzset{%
set my colour/.code={%
\colorlet{mycolour}{colours!!+},
},
my colour/.style={%
set my colour,
bottom color=mycolour,
top color=mycolour!50,
fill opacity=.5,
},
}
\begin{document}
\begin{tikzpicture}
\foreach \i [evaluate={\ii=int(\i-1)}, remember=\i as \ilast] in {0,...,7}{
\foreach \j [evaluate={\jj=int(\j-1)}, remember=\j as \jlast] in {0,...,7}{
\coordinate [shift={(\j,\i)}] (n-\i-\j) at (rand*180:1/4+rnd/8);
\ifnum\i>0
\path [my colour] (n-\i-\j) -- (n-\ii-\j) -- (n-\ilast-\j) -- cycle;
\fi
\ifnum\j>0
\path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\i-\jlast) -- cycle;
\path [my colour] (n-\i-\jlast) -- (n-\i-\jj) -- (n-\i-\j) -- cycle;
\ifnum\i>0
\path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\ii-\j) -- cycle;
\path [my colour] (n-\ilast-\j) -- (n-\ilast-\jj) -- (n-\i-\j) -- cycle;
\pgfmathparse{int(rnd>.5)}
\ifnum\pgfmathresult=0
\path [my colour] (n-\ilast-\jlast) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\ilast-\j) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\i-\jlast) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\ii-\j) -- (n-\i-\jj) -- (n-\i-\j) -- cycle;
\else
\path [my colour] (n-\ii-\j) -- (n-\i-\jj) -- (n-\i-\j) -- cycle;
\path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\i-\jlast) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\ilast-\j) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
\path [my colour] (n-\ilast-\jlast) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
\fi
\fi
\fi
}
}
\end{tikzpicture}
\end{document}


• You are an artist. – AlexG Jun 16 '16 at 12:04
• Wow this is really astonishing! In order to choose a specific color palette, should I work on the \definecolourseries command? Additionally, how to define gradients with two light and dark extremes of the same color inside each triangular area? – linello Jun 16 '16 at 12:16
• It's things like this that continually amaze me with what LaTeX can do. Great work @cfr! – Richard Jun 16 '16 at 12:32
• @linello Yes, take a look at xcolor's documentation for details of how to use colour series. This is one I created for something else and I really just used it here by way of demonstration. I find the documentation a bit difficult to apply, but it gets easier once you've got an example. The !! takes the current colour. The !!+ increments the counter afterwards. The 12 gives the number of steps. – cfr Jun 16 '16 at 14:13
• @linello For the gradient, you would probably be best defining a custom gradient. If you just want 3 colours, you can say left color= , right color= , middle color=  or top... bottom... middle (note that middle must come last - order matters). But for 4 colours, I think you need a custom shading. This is a TikZ/PGF matter, as opposed to xcolor. – cfr Jun 16 '16 at 14:15