答案1
答案2
我忍不住复活了一个阿兰·马特斯的老把戏。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}
\makeatletter
%from https://tex.stackexchange.com/a/14295/121799
\pgfkeys{/pgf/decoration/.cd,
start color/.store in =\startcolor,
end color/.store in =\endcolor,
vertical decrease slope/.store in = \DrasticY,
color slope/.store in = \ColorSensitivity
}
\pgfdeclaredecoration{vertical width and color change}{initial}{
\state{initial}[width=0pt, next state=line, persistent precomputation={%
\pgfmathdivide{50}{\pgfdecoratedpathlength}%
\let\increment=\pgfmathresult%
\pgfmathsetmacro{\orilinewidth}{\pgflinewidth}%
\pgfmathsetmacro{\ynod}{\pgf@y}%
\def\x{0}%
}]{}
\state{line}[width=.5pt, persistent postcomputation={%
\pgfmathsetmacro{\x}{\the\pgf@y-\ynod}%
}]{%
\pgfmathsetmacro{\newlinewidth}{max(\DrasticY*\x*0.075pt+\orilinewidth,0)}%
\pgfsetlinewidth{\newlinewidth}
\pgfsetarrows{-}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfqpoint{.75pt}{0pt}}%
\pgfmathtruncatemacro{\absx}{round(100*(1-min(max(\ColorSensitivity*(\x+28),0),1)))}
\pgfsetstrokecolor{\endcolor!\absx!\startcolor}%
\pgfusepath{stroke}%
}
\state{final}{%
\pgfsetlinewidth{\pgflinewidth}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfmathtruncatemacro{\absx}{round(100*(1-min(max(\ColorSensitivity*(\x+28),0),1)))}
\color{\endcolor!\absx!\startcolor}%
\pgfusepath{stroke}%
}
}
\makeatother
\begin{tikzpicture}
\begin{scope}
\draw[ line width=0.5cm, decoration={vertical width and color change,
start color=black, end color=black,vertical decrease slope=0.8,color slope=0.025}, decorate] (10cm,1cm) -- (12cm,1cm)
arc(90:-90:1.3cm and 0.943cm)
to (10cm,-0.885cm);
\end{scope}
\begin{scope}[xshift=5cm]
\draw[ line width=0.5cm, decoration={vertical width and color change,
start color=blue, end color=black,vertical decrease slope=3.8,color slope=0.02}, decorate] (10cm,1cm) -- (12cm,1cm)
arc(90:-90:1.3cm and 0.943cm)
to (10cm,-0.885cm);
\end{scope}
\end{tikzpicture}
\end{document}
我们可以通过调整来控制线宽减少的量vertical decrease slope
,甚至可以改变颜色。