4

When I try to use scope fading, in a scope, it seems to clip the rest of the scope that is not inside the fading rectangle. Interestingly, it seems to clip it at a random place.

Some code and pictures:

\documentclass[tikz,margin=5em]{standalone}
\usepackage{intcalc,calc}
\usepackage{tikz}
\usepackage{verbatim}

\usetikzlibrary{fadings}
\title{Tex.Scope.Fading.Minimal}

\begin{document}
\tikzset{wline/.style={rounded corners,line width=1mm,color=blue!40!black}}
    \begin{tikzpicture}[]
      \begin{scope}[]
        \draw[wline] (0,0) rectangle (5,5);
        %commented, no fading
        %\path[scope fading=west] (-1,0) rectangle (1,10);
        \draw[wline] (4,0) -- (4,3) -- (-2,3);
        \draw[wline] (5,0) -- (5,4) -- (-2,4);
      \end{scope}
    \end{tikzpicture}


    \begin{tikzpicture}[]
      \begin{scope}[]
        \draw[wline] (0,0) rectangle (5,5);
        \path[scope fading=west] (-1,0) rectangle (1,5);
        \draw[wline] (4,0) -- (4,3) -- (-2,3);
        \draw[wline] (5,0) -- (5,4) -- (-2,4);
      \end{scope}
    \end{tikzpicture}
\end{document}

First image:

enter image description here

And this is second image, with fading:

enter image description here

Questions:

Why is it clipping the rest of that?

Why is it clipping there of all places, that isn't even the rectangle-path's boundary?

How do I get what I want to happen?

What I want it to do is actually have a [scope fading=west] rectangle and a [scope fading=south] rectangle on the bottom, and leave everything (read: all parts of things) that lie outside those rectangles fully opaque.

  • 2
    Welcome to TeX.SX! Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Nov 13 '13 at 11:10
  • @Jubobs oh, is that necessary if I linked to writelatex at the bottom? – Realz Slaw Nov 13 '13 at 11:17
  • @Ignasi oh good point on that. I edited that point out of the question. – Realz Slaw Nov 13 '13 at 11:20
  • 1
    @RealzSlaw Yes. It's best if you're question is self-contained. – jub0bs Nov 13 '13 at 11:41
  • @Jubobs OK I done it. – Realz Slaw Nov 13 '13 at 11:43
4

Every fading has a prescribed effective region and out of that, it's not rendered. Example;

\tikzset{wline/.style={rounded corners,line width=1mm,color=blue!40!black}}
    \begin{tikzpicture}[]
      \begin{scope}[]
        \draw[wline] (0,0) rectangle (5,5);
        \draw[thick,red,scope fading=west,fading angle=45] (-1,0) rectangle (1,5);
        \draw[wline] (4,0) |- (-2,3);
        \draw[wline] (5,0) |- (-2,4);
      \end{scope}
    \end{tikzpicture}

This shows that when you rotate the fading you get a little more faded path on the second line.

enter image description here

Let's grab some shading that shows how the effective region is formulated (directly from the manual with minor changes)

\usetikzlibrary{fadings}
\pgfdeclareradialshading{myshading}{\pgfpointorigin}
{
color(0mm)=(pgftransparent!0);
color(5mm)=(pgftransparent!0);
color(8mm)=(pgftransparent!100);
color(40mm)=(pgftransparent!0)
}
\pgfdeclarefading{fading3}{\pgfuseshading{myshading}}

\tikzset{wline/.style={rounded corners,line width=1mm,color=blue!40!black}}
    \begin{tikzpicture}[]
      \begin{scope}[]
        \draw[wline] (0,0) rectangle (5,5);
        \draw[thick,red,scope fading=fading3] (-1,0) rectangle (1,5);
        \draw[wline] (4,0) |- (-2,3);
        \draw[wline] (5,0) |- (-2,4);
      \end{scope}
    \end{tikzpicture}

Notice where 40 mm hits your upper cornered path. So your second question is not entirely correct. The clipping is due to this; if the fading is not defined beyond certain measurements it is not drawn because the fading is stretched or shrunk to your path as a layer.

enter image description here

Long story short your fading defining path should be large enough to cover your to-be-faded paths. If you want to have fixed sized fadings you need fit fading set to be false such that no matter what the fading path is the fading has the same measurements to apply. This is particularly useful if you have custom, fine tuned fadings

\tikzset{wline/.style={rounded corners,line width=1mm,color=blue!40!black}}
    \begin{tikzpicture}[]
      \begin{scope}[]
        \draw[wline] (0,0) rectangle (5,5);
        \path[scope fading=west] (-1,0) rectangle (5,5);
        \draw[wline] (4,0) |- (-2,3);
        \draw[wline] (5,0) |- (-2,4);
      \end{scope}
    \end{tikzpicture}

enter image description here

  • The issue is, I don't want the fade to start across the entire image; I want it to start on the left 2 cm. – Realz Slaw Nov 13 '13 at 23:34
2

I can answer part of your question. Regarding to scope fading, in TiKZ manual you can read:

The only difference is, that the effect of the fading will persist after the current path till the end of the scope. Thus, the fading is applied to all subsequent drawings in the current scope, not just to the current path. In this regard, the option works very much like the clip option.

So, it's normal that everything drawn after \path[scope fading=... line appears clipped.

A not so nice solution would be to draw everithing twice, one before fading and another one after that. Probably not what you want but it's the best I can do.

\documentclass[tikz,margin=5em]{standalone}
\usepackage{intcalc,calc}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{fadings}

\tikzset{wline/.style={rounded corners,line width=1mm,color=blue!40!black}}

\begin{tikzfadingfrompicture}[name=logo]
\shade[left color= transparent!0,
right color=transparent!100] (0,0) rectangle (2,5);
\end{tikzfadingfrompicture}

\title{Tex.Scope.Fading.Minimal}

\begin{document}\begin{tikzpicture}[]
    \draw[wline] (0,0) rectangle (5,5);
    \draw[wline] (4,0) -- (4,3) -- (-2,3);
    \draw[wline] (5,0) -- (5,4) -- (-2,4);
    \path[scope fading=logo] (-1,0) rectangle (1,5);
    \draw[wline,white,transparent!0] (0,0) rectangle (5,5);
    \draw[wline,transparent!0] (4,0) -- (4,3) -- (-2,3);
    \draw[wline,transparent!0] (5,0) -- (5,4) -- (-2,4);
\end{tikzpicture}
\end{document}

enter image description here

  • (bold mine) "Thus, the fading is applied to all subsequent drawings in the current scope, not just to the current path. In this regard, the option works very much like the clip option": this is what I want to happen, I want it to APPLY to all subsequent drawings, not to actually go ahead and CLIP all subsequent drawings! :madface: But yes, I am aware of this type of solution, and have been doing that a bit; it is quite annoying though. But you say "So, it's normal that everything drawn after \path[scope fading=... line appears clipped."; from my interpretation, it is not. – Realz Slaw Nov 13 '13 at 17:59

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.