Original question title - "Fade from specific point using fadings TikZ"
How can I fade out from a specific point on an object? I want to apply two fadings to this red square. Consider this MWE:
\documentclass[tikz,margin=5pt]{standalone}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\fill [red] (0,0) rectangle (5,5);
\draw [black] (4,0)--(4,5);
\draw [black] (1,0)--(1,5);
\draw [->,line width=1mm] (4,-0.3)--(5,-0.3);
\draw [->,line width=1mm] (1,-0.3)--(0,-0.3);
\end{tikzpicture}
\end{document}
I want to fade out to 100% transparency, but only starting at the black lines and then out to left and right edges (as indicated by the arrows).
For this simple example, I can achieve the effect I'm looking for by re-drawing this diagram as three separate rectangles. Keeping the centre rectangle solid red
, and applying path fading=west
and path fading=east
to the left and right rectangles respectively. But this doesn't seem very elegant. And is not practical for a more complicated shape I am working on.
What I want to achieve
\documentclass[tikz,margin=5pt]{standalone}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\fill [red,path fading=west] (0,0) rectangle (1,5);
\fill [red] (1,0) rectangle (4,5);
\fill [red,path fading=east] (4,0) rectangle (5,5);
\draw [black] (4,0)--(4,5);
\draw [black] (1,0)--(1,5);
\draw [->,line width=1mm] (4,-0.3)--(5,-0.3);
\draw [->,line width=1mm] (1,-0.3)--(0,-0.3);
\end{tikzpicture}
\end{document}
Is there a better way of doing this?
UPDATE
The reason the 'splitting up' method doesn't work for me is because I have more complicated elements of my tikzpicture
. Consider having an image overlaid on the red square. How can the fading also apply to it?
Perhaps the fadings
package is not what I'm after...?
\documentclass[tikz,margin=5pt]{standalone}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\fill [red] (0,0) rectangle (5,5);
\node at (2.5,2.5) (Image) {\includegraphics[width=5cm]{example-image.pdf}};
\draw [black] (4,0)--(4,5);
\draw [black] (1,0)--(1,5);
\draw [->,line width=1mm] (4,-0.3)--(5,-0.3);
\draw [->,line width=1mm] (1,-0.3)--(0,-0.3);
\end{tikzpicture}
\end{document}