I want to draw in tikz a line that diffuses and a dashed path that is basically the contour of this diffused area. I think that in photoshop the diffusing effect can be done by a blurred stroke.

Is this possible?

Here is a very badly hand-drawn example:



Thanks to the help of @percusse and @Alenanno I was able to produce almost exactly what I wanted. The only thing missing is a dashed line around the shaded area instead of the full gray line that I hacked in.

Image with desired effect

Code here:



    \def\lc{0.6} %Transition: 5-linear %0-infinitely sharp
    \def\psz{1.0} %Potato size
    \def\smss{0.92} %Smoothness: number of colors=1/(1-\smss)


    %Crack path
    \def\Ax{0} \def\Ay{0}
    \def\Bx{1.5}    \def\By{2}
    \def\Cx{4.5}    \def\Cy{4}
    \def\Dx{6}  \def\Dy{6}  
    \def\Ex{6}  \def\Ey{4}  
    \def\Fx{8}  \def\Fy{3}  

        \clip plot [smooth cycle, tension =0.8] coordinates{ \potato{\psz}};
        \draw[line cap=round,line width=105pt, black!20] plot [smooth,tension=1] coordinates{ \linepath};
        \draw[line cap=round,line width=105pt, black!20] plot [smooth,tension=1] coordinates{ \linepathnb};
        \foreach \x[evaluate={\xc=90*(exp(-\x/\lc)-0.9*exp(-1/\lc)*\x;}] in {1,\smss,...,0}{
            \draw[line cap=round,line width=\x*100pt,black,draw=black!\xc] plot [smooth,tension=1] coordinates{ \linepath};
            \draw[line cap=round,line width=\x*100pt,black,draw=black!\xc] plot [smooth,tension=1] coordinates{ \linepathnb};
        \draw[line cap=round,line width=2pt, black] plot [smooth,tension=1] coordinates{ \linepath};
        \draw[line cap=round,line width=2pt, black] plot [smooth,tension=1] coordinates{ \linepathnb};
    \draw [line width=5pt] plot [smooth cycle, tension =0.8] coordinates{ \potato{\psz}};


  • 2
    Take a look at the fadings and shadings libraries. What do you have so far? If you post your own attempt, you are more likely to get answers. I don't think you can blur a line in TikZ. You most probably need to use a fill. – cfr May 13 '15 at 2:03
  • I think cfr means what kind of approach you have, than we could find the answer. For example is that the fading changing with data? or with function? Furthermore, in tikz, links are solid, and only the area filled with color could fade. – selwyndd21 May 13 '15 at 3:28
  • 1
    Related? tex.stackexchange.com/questions/108817/… – Ignasi May 13 '15 at 6:55
  • 1
    Glowing path = Laser beam ? tex.stackexchange.com/a/80207/14500 ... – Paul Gaborit May 15 '15 at 23:14
  • @PaulGaborit Ah, I completely missed your answer. Sorry about that. – percusse May 16 '15 at 13:55

You can use the idea behind the pgf-blur package (originated from the question Reuse of soft path in fading declaration? Transformation of fadings? ) that utilizes for smooth shadows : draw over and over with changing the color (or opacity as you wish) and shape size (or line width for paths). The step size can be changed to make it smoother.

I cooked up a formula that looked OK to my eyes but you can go more rigorous for the decay rate and so on.

\foreach \x[evaluate={\xc=0.5*100*ln(10/\x);}] in {10,9.9,...,1}{
\draw[line cap=round,line width=\x*1pt,draw=black!\xc]
(0,0) arc (0:30:1 and 2) to[bend left] (3,2) arc (0:250:1 and 1) -- cycle;

enter image description here

| improve this answer | |
  • Oooh, so there is a package. I was trying to adapt another solution but it was harder than expected. – Alenanno May 15 '15 at 21:03

As far as I know, you cannot shade a path the way you have it in your question. You could use a path to clip a shaded shape beneath it, but it wouldn't achieve your result because it's curved and the shading follows the curve.

However, you can blur the line elsewhere and include it as an external image. If it's your only instance of such a graphic, then it's not that time-consumming, but if you don't have multiple types throughout a document, then you might do the dashed line in an external program (it's easy to select a -blurred- shape and apply a contour).

If you did the dashed curve using a graphics editing program along the contour of a blurred stroke, then it would be much more precise than the example below. After that, you would only need to include it in a simple shape in Tikz.

This solution uses a tweaked version of JLDiaz's solution.


figure 1



\newcommand\fillshape[3]{ % #1 = shape, #2 = filename of texture, #3 = includegraphics options
        \clip #1;
        \node[yshift=-2.6em] {\includegraphics[#3]{#2}};
        \draw[densely dashed,line width=.2pt] (.43,-1.5) 
            to[out=77,in=255,looseness=1.6,yshift=1.3] (.1,-.2) 
            to[out=65,in=69,looseness=1.7] (-.45,.05)
            to[out=249,in=95,looseness=.7] (-.55,-.6)
            to[out=275,in=70,looseness=1.1,yshift=1.3] (-.15,-1.6);
    \draw[line width=.5pt] #1;


\fillshape{(0,0) circle (1.5cm)}{line}{width=2cm};
| improve this answer | |
  • Thank you. I agree that using an external program will probably be the easiest way. I just wanted to try to have something vectorized because I'm going to include this in my thesis. If no one figures out a way of doing this fully on tikz I'll accept your answer. Thanks again. – Miguel May 14 '15 at 15:22

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.