我在 StackExchange 上找到了下面的 tikzset,我想修改它以接受除了管道宽度之外的更多参数,我希望能够更改它pipe width={(\pipewidth)*4/3}
以及颜色;即draw=black!70!white!\j!white
。我希望较小的管道具有不同的颜色和不同的连接尺寸。
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.markings,decorations.pathreplacing,calc}
\makeatletter
\tikzset{every pipe/.code={%
\pgfmathloop
\ifnum\pgfmathcounter>20
\else
\pgfmathsetmacro\i{\pgfmathcounter}%
\pgfmathsetmacro\j{80-\pgfmathcounter*3}%
\tikzset{preaction/.expanded={line width=(\pipewidth)*(1-\i*\i/500),
draw=black!50!white!\j!white}}%
\repeatpgfmathloop
},
every flange/.style 2 args={insert path={
let \p1=(#1), \p2=(#2),\n1={atan2(\y2-\y1, \x2-\x1)} in
[shift={(\p1)}, rotate=\n1, pipe width={(\pipewidth)*4/3}, every pipe]
(0.01,0) -- (0.2,0)
}},
flanges/.style={postaction={%
/utils/exec={
\@for\pos:=#1\do{%
\tikzset{decoration/.expanded={markings,
mark=at position \pos\space with {
\noexpand\path [pipe width=\pipewidth*4/3, every pipe] (0.01,0) -- (0.2,0);
}}}}},
decorate}},
pipe width/.code=\pgfmathsetlengthmacro\pipewidth{#1},
pipes/.style={
every pipe,
postaction={decoration={show path construction,
lineto code={
\path [every flange={\tikzinputsegmentfirst}{\tikzinputsegmentlast}];
\path [every flange={\tikzinputsegmentlast}{\tikzinputsegmentfirst}];
},
curveto code={
\path [every flange={\tikzinputsegmentfirst}{\tikzinputsegmentsupporta}];
\path [every flange={\tikzinputsegmentlast}{\tikzinputsegmentsupportb}];
}
}, decorate}},
pipe/.style={
every pipe,
flanges={0, 1}
}}
\begin{document}
\begin{tikzpicture}[line join=round]
\path [pipe width=0.8cm, pipes] (0,6) -- (0,1) arc (180:270:2)--(5,-1);
\path [pipe width=0.1cm, pipes] (0.2,6) -- (0.2,1.15) arc (180:270:2)--(5,-0.75);
\end{tikzpicture}
\end{document}