# Tikz: fading a snake curve

Trying to adapt this answer by percusse: https://tex.stackexchange.com/a/134297/3929 for a path that has a snake decoration.

It sort of works, but I'd like the curve to uniform thickness. In the image below it more or less looks like the the curve is drawn with a caligraphic pen.

Any ideas?

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}

\path(-0.2cm,0.2cm) rectangle (1.2cm,2.5cm); % Arrow line is an overlay!
\pgfinterruptboundingbox
\draw[
very thick,
transparent!20,
decorate,decoration=snake,
line around/.style={
decoration={
pre=curveto,
pre length=0*#1,
post length=#1,
},
},
line around=3pt,
->] (0cm,0cm) -- ++ (0,2cm);
\endpgfinterruptboundingbox

\begin{document}

\begin{tikzpicture}
\draw[
draw=none,
top color=red,
bottom color=blue,
] (0,0) rectangle (1cm,-2cm);
\end{tikzpicture}

\end{document}


• Does percusse's code produce the expected result for you? Because I cannot replicate the output shown in that answer with the code posted there. This could be due to changes in TikZ. That answer is quite old in TikZ terms. – cfr Jun 17 '16 at 23:25

The code in the answer by percusse linked in the question does not actually work for me. I'm guessing this is due to changes in TikZ. 2013 is essentially ancient history in TikZ terms.

I think the problem here is that you do not want TikZ to fit the fading as it does by default. Then you just need to make sure that things fit appropriately to get the expected result.

Note that

    line around/.style={
decoration={
pre=curveto,
pre length=0*#1,
post length=#1,
},
},
line around=3pt,


is equivalent to

  decoration={
pre=curveto,
pre length=0pt,
post length=#3pt,
},


and I'm not entirely sure what the idea behind this code is so I've removed it for simplicity in the example.

\documentclass[tikz,border=10pt,multi]{standalone}
% question by daleif at https://tex.stackexchange.com/q/315284/
% OP's code is based on percusse's answer at https://tex.stackexchange.com/a/134297/3929

\path [fill=transparent!100] (-5mm,-10mm) rectangle (5mm,10mm);
\draw[
very thick,
transparent!20,
decorate,
decoration=snake,
decoration={
pre=curveto,
pre length=0pt,
post length=3pt,
},
->
] (0,-1cm) -- ++ (0,2cm);
\begin{document}
\begin{tikzpicture}
\path[
top color=red,
bottom color=blue,
] (-5mm,-10mm) rectangle (5mm,10mm);
\end{tikzpicture}
\end{document}


However, this is not so far very satisfactory.

• The code worked, but I get the result in the image, which clearly does not look like yours (around the turns), using TL15 frozen – daleif Jun 18 '16 at 5:22
• @daleif Do you get the image in your question from the code in my MWE? That is, exactly my MWE? I'm using TL 2016. – cfr Jun 18 '16 at 12:59
• @daleif I get the same result with TL2015 frozen as with TL2016. – cfr Jun 18 '16 at 13:15
• The image I posted is exactly from my mwe. We are finishing a project, so I'm going to keep it in TL15 – daleif Jun 18 '16 at 13:15
• @daleif You need to read the stuff on how TikZ/PGF fits a shading to a path, which is how it fits a fading to a path also. The rectangle is just to ensure the background is painted black. Possibly you can drop this. I said it is not very satisfactory because I can't think this is a good method precisely because it is difficult to move. Not fitting a fading is mentioned specifically as useful for exceptional cases such as knocking out, so that's possibly right. But I don't think it should make it unmoveable - just unscalable. – cfr Jun 20 '16 at 11:59