![我怎样才能使淡入淡出始终透明,而忽略下面所绘制的内容?](https://linux22.com/image/413596/%E6%88%91%E6%80%8E%E6%A0%B7%E6%89%8D%E8%83%BD%E4%BD%BF%E6%B7%A1%E5%85%A5%E6%B7%A1%E5%87%BA%E5%A7%8B%E7%BB%88%E9%80%8F%E6%98%8E%EF%BC%8C%E8%80%8C%E5%BF%BD%E7%95%A5%E4%B8%8B%E9%9D%A2%E6%89%80%E7%BB%98%E5%88%B6%E7%9A%84%E5%86%85%E5%AE%B9%EF%BC%9F.png)
]
在我的代码中,我有一个使用先前定义的自定义淡入淡出的路径。它应该淡化当前范围的边框,但如您所见,这仅在只有一个填充时才会发生。当我叠加多个填充时,它们的总不透明度会复合,边框会变得越来越淡。我该如何避免这种情况?我知道,在这个例子中,解决方案是简单地改变矩形的开始和结束位置,但这只是一个例子,因为我想将这个概念应用于更复杂的图形,在这些图形中,计算何时开始填充以避免这个问题实际上是不可行的。作为一个附加问题,我怎样才能阻止蓝色填充影响红色部分,反之亦然?以下是图片的代码:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzfadingfrompicture}[name=my fading]
\shade[inner color=transparent!0,outer color=transparent!100] (0.5,0.5) circle (0.5);
\shade[inner color=transparent!0,outer color=transparent!100] (7.5,7.5) circle (0.5);
\shade[inner color=transparent!0,outer color=transparent!100] (7.5,0.5) circle (0.5);
\shade[inner color=transparent!0,outer color=transparent!100] (0.5,7.5) circle (0.5);
\shade[top color=transparent!0,bottom color=transparent!100] (0.5,0.5) rectangle (7.5,0);
\shade[right color=transparent!0,left color=transparent!100] (0.5,7.5) rectangle (0,0.5);
\shade[bottom color=transparent!0,top color=transparent!100] (0.5,7.5) rectangle (7.5,8);
\shade[left color=transparent!0,right color=transparent!100] (7.5,0.5) rectangle (8,7.5);
\fill[transparent!0] (0.5,0.5) rectangle (7.5,7.5);
\end{tikzfadingfrompicture}
\begin{tikzpicture}
\clip (0,0) rectangle (8,8);
\fill (0,0) rectangle (8,8);
\path [scope fading=my fading, fit fading=false,fading transform={shift={(current bounding box.center)}}];
\fill[blue] (0,0) rectangle (8,8);
\fill[blue] (0,0) rectangle (8,4);
\fill[blue] (0,0) rectangle (8,2);
\fill[red] (0,0) rectangle (8,1);
\fill[blue] (0,0) rectangle (8,0.5);
\draw[->,thick,red] (1,5) -- (0.25,4.25);
\draw[->,thick,red] (1,3) -- (0.25,2.25);
\draw[->,thick,red] (1,2) -- (0.25,1.25);
\end{tikzpicture}
\end{document}
答案1
欢迎!好问题!你需要把东西放在transparency group
.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzfadingfrompicture}[name=my fading]
\shade[inner color=transparent!0,outer color=transparent!100] (0.5,0.5) circle (0.5);
\shade[inner color=transparent!0,outer color=transparent!100] (7.5,7.5) circle (0.5);
\shade[inner color=transparent!0,outer color=transparent!100] (7.5,0.5) circle (0.5);
\shade[inner color=transparent!0,outer color=transparent!100] (0.5,7.5) circle (0.5);
\shade[top color=transparent!0,bottom color=transparent!100] (0.5,0.5) rectangle (7.5,0);
\shade[right color=transparent!0,left color=transparent!100] (0.5,7.5) rectangle (0,0.5);
\shade[bottom color=transparent!0,top color=transparent!100] (0.5,7.5) rectangle (7.5,8);
\shade[left color=transparent!0,right color=transparent!100] (7.5,0.5) rectangle (8,7.5);
\fill[transparent!0] (0.5,0.5) rectangle (7.5,7.5);
\end{tikzfadingfrompicture}% <- the % removes spurious space
\begin{tikzpicture}
\clip (0,0) rectangle (8,8);
\fill (0,0) rectangle (8,8);
\path [scope fading=my fading, fit fading=false,
fading transform={shift={(current bounding box.center)}}];
\begin{scope}[transparency group]
\fill[blue] (0,0) rectangle (8,8);
\fill[blue] (0,0) rectangle (8,4);
\fill[blue] (0,0) rectangle (8,2);
\fill[red] (0,0) rectangle (8,1);
\fill[blue] (0,0) rectangle (8,0.5);
\draw[->,thick,red] (1,5) -- (0.25,4.25);
\draw[->,thick,red] (1,3) -- (0.25,2.25);
\draw[->,thick,red] (1,2) -- (0.25,1.25);
\end{scope}
\end{tikzpicture}
\end{document}