Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My question was inspired by Rotate fading in tikz where the inquiror is drawing laser beams that shall look somewhat blurred not as lines but as boxes with a fading. The problem with this approach is that the fading has to be turned according to the orientation via quite unhandy canvas transformations. Above that curved lines are not possible this way.

That made me think if there is way to draw fading or blurred lines in a more convenient manner, maybe by applying some kind of very closely repeated decoration template to a path? Any ideas?

share|improve this question
    
I can imagine that in a curvy line those small steps would cause a lot of aliasing problems. –  percusse Nov 2 '12 at 21:21
add comment

2 Answers

up vote 8 down vote accepted

Here is a proposition using recursive preaction (each of the ten preactions draws the path with draw opacity=.1 and line width increased by .2pt):

enter image description here

\documentclass{standalone}
\usepackage{ifthen}
\usepackage{tikz}
\tikzset{
  laser beam action/.style={
    line width=\pgflinewidth+.2pt,draw opacity=.1,draw=#1,
  },
  laser beam recurs/.code 2 args={%
    \pgfmathtruncatemacro{\level}{#1-1}%
    \ifthenelse{\equal{\level}{0}}%
    {\tikzset{preaction={laser beam action=#2}}}%
    {\tikzset{preaction={laser beam action=#2,laser beam recurs={\level}{#2}}}}
  },
  laser beam/.style={preaction={laser beam recurs={10}{#1}},draw opacity=1,draw=#1},
}
\begin{document}
\begin{tikzpicture}
  \fill[lime] circle(1cm);
  \path[preaction={fill=black},laser beam=yellow,] (1,2) circle(1cm and 5mm);
  \path[laser beam=red] (0,0) -- (2,2);
  \path[rounded corners=5mm,laser beam=blue] (0,0) -- (3,0) -- (0,-2);
  \path[line width=4pt,laser beam=orange] (0,0) -- (-1,2);
\end{tikzpicture}
\end{document}
share|improve this answer
    
Very nice solution! –  Benedikt Bauer Nov 3 '12 at 11:44
add comment

Since the proposed solution seemed to be too complicated if only straight lines should be drawn, I gave it another shot and came up with the following solution that involves the shadings library and canvas transformation:

MWE:

\documentclass[tikz,convert={density=400,outext=.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadings} % libraries for this TikZ picture
\begin{document}
\begin{tikzpicture}
    \draw (0,0) rectangle (2,2);
    \begin{scope}[transform canvas={rotate=30}] % rotate by 30 degree
        \shade[shading=axis,bottom color=white,top color=white,middle color=black,shading angle=0] (1,0) rectangle (2,0.2);
    \end{scope}
\end{tikzpicture}
\end{document}

Output:

Line with fading, rotated by 30 degree

This answer is inspired by this answer of user rgallego.

share|improve this answer
    
But this solution does only work as long as lines (which you "simulate" by rectangles) are straight, right? What about curved lines? –  Benedikt Bauer Mar 10 at 14:09
    
@BenediktBauer You are absolutely right. I updated the answer accordingly. –  Peter Pablo Mar 10 at 14:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.