更改 tikzpicture 阴影中的渐变

更改 tikzpicture 阴影中的渐变

我希望红色渐变从后面开始朝向中心(因此渐变不再是线性的而是指数的),并且渐变中心向下拉而不是位于中心。

在此处输入图片描述

我希望你能帮助

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
    \path[use as bounding box] (0,0) rectangle (6,6);       

    \coordinate (A1) at (2.5,5);
    \coordinate (B1) at (2,1);
    \coordinate (A2) at (4 , 5);
    \coordinate (B2) at (4.5 ,1);
    \shade[inner color=red,outer color=white,fill opacity=0.8]  (A2) to [bend right=10] (B2) to [] (B1) to [bend right=10] (A1) to (A2);

    \end{tikzpicture}

\end{document}

答案1

pgflibraryfadings.code.tex文件中,您可以使用以下代码片段设置垂直阴影选项。

\pgfdeclareverticalshading{pgf@lib@fade@north}{100bp}
{color(0bp)=(pgftransparent!0);
color(25bp)=(pgftransparent!0);
color(75bp)=(pgftransparent!100);
color(100bp)=(pgftransparent!100)}% 

使用pgftransparentcolor值,我得到了以下输出。

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\makeatletter
\pgfdeclareverticalshading{pgf@lib@fade@north}{100bp}
{color(0bp)=(pgftransparent!0);
 color(5bp)=(pgftransparent!10);
 color(60bp)=(pgftransparent!100); color(70bp)=(pgftransparent!100)}%
\pgfdeclarefading{myfade}{%
  \pgfuseshading{pgf@lib@fade@north}%
}
\makeatother
\begin{document}

\begin{tikzpicture}
  \path[use as bounding box] (0,0) rectangle (6,6);       

    \coordinate (A1) at (2.5,5);
    \coordinate (B1) at (2,1);
    \coordinate (A2) at (4 , 5);
    \coordinate (B2) at (4.5 ,1);
    \fill[red,path fading=myfade]  (A2) to [bend right=10] (B2) to [] (B1) to [bend right=10] (A1) to (A2);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

附录:对于垂直和水平阴影,可以\pgfdeclarehorizontalshading一起使用这些选项。

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\makeatletter
\pgfdeclareverticalshading{pgf@lib@fade@north}{100bp}
{color(0bp)=(pgftransparent!0);
 color(5bp)=(pgftransparent!10);
 color(60bp)=(pgftransparent!100);
 color(70bp)=(pgftransparent!100)}%
\pgfdeclarefading{myfadev}{%
  \pgfuseshading{pgf@lib@fade@north}%
}
\makeatother

\makeatletter
\pgfdeclarehorizontalshading{pgf@lib@fade@north}{100bp}
{color(0bp)=(pgftransparent!0);
 color(5bp)=(pgftransparent!10);
 color(60bp)=(pgftransparent!100);
 color(90bp)=(pgftransparent!100)}%
\pgfdeclarefading{myfadeh}{%
  \pgfuseshading{pgf@lib@fade@north}%
}
\makeatother

\begin{document}

\begin{tikzpicture}
  \path[use as bounding box] (0,0) rectangle (6,6);       

    \coordinate (A1) at (2.5,5);
    \coordinate (B1) at (2,1);
    \coordinate (A2) at (4 , 5);
    \coordinate (B2) at (4.5 ,1);
    \fill[red,path fading=myfadev]  (A2) to [bend right=10] (B2) to [] (B1) to [bend right=10] (A1) to (A2);
    \fill[red,path fading=myfadeh]  (A2) to [bend right=10] (B2) to [] (B1) to [bend right=10] (A1) to (A2);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容