Tikz 多重淡入淡出范围

Tikz 多重淡入淡出范围

如何定义范围并使用 Tkiz 或类似的东西进行多次淡入淡出?我想要做的是:

这个图片

我用的是svg2tkiz工具来转换svg,但它给了我一个例外,只处理路径,而不是颜色。然后我稍微修改了一下,得到了这个:

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\definecolor{lineBlue}{RGB}{37,102,176}
\definecolor{gradientBlue}{RGB}{55,123,191}

% fading speed
% <http://tex.stackexchange.com/a/49802/20977>
\makeatletter
\tikzset{
    fading speed/.code={
        \pgfmathtruncatemacro\tikz@startshading{50-(100-#1)*0.25}
        \pgfmathtruncatemacro\tikz@endshading{50+(100-#1)*0.25}
        \pgfdeclareverticalshading[%
            tikz@axis@top,tikz@axis@middle,tikz@axis@bottom%
        ]{axis#1}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@startshading)=(tikz@axis@bottom);
            color(50bp)=(tikz@axis@middle);
            color(\tikz@endshading)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)
        }
        \tikzset{shading=axis#1}
    }
}
\makeatother

\begin{tikzpicture}[y=0.50pt,x=0.50pt,yscale=-1, inner sep=0pt, outer sep=0pt]
% path12 - Blue Circle
\path[draw=lineBlue,line width=5.152pt, color=lineBlue]
    (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390) -- cycle;

%\filldraw[gradientBlue, top color=black!20, bottom color=gradientBlue!30, middle color=gradientBlue]
\fill[black, top color=white, bottom color=gradientBlue, fading speed=50]
    (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390)
    -- cycle;

\end{tikzpicture}
\end{document}

但是此代码只是模仿了淡入淡出效果的顶部,淡入淡出效果一直持续到图像的中间。我可能需要一个范围,将完整的淡入淡出效果应用到图像的中间。

tikz 图像

答案1

我使用了该\clip命令并制作了两次“淡入淡出”,一次与另一次相反,以获得所需的效果。

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\definecolor{lineBlue}{RGB}{37,102,176}
\definecolor{gradientBlue}{RGB}{55,123,191}


\makeatletter
\tikzset{
    fading speed/.code={
        \pgfmathtruncatemacro\tikz@startshading{50-(100-#1)*0.25}
        \pgfmathtruncatemacro\tikz@endshading{50+(100-#1)*0.25}
        \pgfdeclareverticalshading[%
            tikz@axis@top,tikz@axis@middle,tikz@axis@bottom%
        ]{axis#1}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@startshading)=(tikz@axis@bottom);
            color(50bp)=(tikz@axis@middle);
            color(\tikz@endshading)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)
        }
        \tikzset{shading=axis#1}
    }
}
\makeatother

\begin{tikzpicture}[y=0.50pt,x=0.50pt,yscale=-1, inner sep=0pt, outer sep=0pt]
% Border
\path[draw=lineBlue,line width=5.152pt, color=lineBlue]
    (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390) -- cycle;
% Inside gradient
\begin{scope}\clip (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390) -- cycle;
\fill[black, top color=white, bottom color=gradientBlue, fading speed=50] (31,12) rectangle (440,168.5);
\fill[black, top color=gradientBlue, bottom color=white, fading speed=50] (31,168.5) rectangle (440,329);
\end{scope}
\end{tikzpicture}
\end{document}

结果:

在此处输入图片描述

请注意,一旦您给出了\clip一条路径,该路径内的所有内容scope都会被该路径剪切。

我根据用于定义边界的 x 和 y 值的最大值和最小值来选择“褪色”矩形的边界点,在本例中分别为 440 和 31,以及 329 和 12。然后我取最大 y 值的中点,即 168.5,并将其用作形状的中点。我想通过使矩形更高,您可以让渐变一直延伸到图像的底部和顶部。

最后,根据我所用的查看方式,我在形状中间看到一条细黑线,我不确定是什么原因造成的(在预览中,但不是在 Acrobat 中)。要永久摆脱它,请在环境\draw[color=gradientBlue, line width=5pt] (31,168.5)--(440,168.5);内部的scope两个矩形后面放置类似的东西。

相关内容