曲线阴影矩形

曲线阴影矩形

我想重现这个数字:

在此处输入图片描述

为了做到这一点,我只能用以下代码来制作阴影矩形:

\draw [bottom color=gray,top color=gray,middle color= white] (0,0) rectangle (3,0.3);

这给了我:

在此处输入图片描述

如果我想用这种图案制作四分之一圆的边框,是否可以制作一个具有可调角度和长度的弯曲矩形?

提前致谢。

答案1

像这样吗?

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations} 
\newcounter{icoord}
\pgfkeys{/tikz/.cd,
    curved pipe/.cd,
    radius/.store in=\CurvedPipeRadius,
    radius=10pt,
    step/.store in=\CurvedPipeStep,
    step=1pt,
    shade/.style={left color=gray,right color=gray,middle color=white}
}

\pgfdeclaredecoration{curved pipe}{initial}
{% 
\state{initial}[width=\CurvedPipeStep,next state=cont] {%
    \pgfmoveto{\pgfpoint{\CurvedPipeStep}{\CurvedPipeRadius}}%
    \pgfpathlineto{\pgfpoint{0.3\pgflinewidth}{\CurvedPipeRadius}}%
    \setcounter{icoord}{0}%
    \pgfcoordinate{lastup-\number\value{icoord}}{\pgfpoint{1pt}{\CurvedPipeRadius}}%
    \pgfcoordinate{lastdown-\number\value{icoord}}{\pgfpoint{1pt}{-1*\CurvedPipeRadius}}%
  }
  \state{cont}[width=\CurvedPipeStep]{%
     \stepcounter{icoord}%
    \pgfcoordinate{lastup-\number\value{icoord}}{\pgfpoint{\CurvedPipeStep}{\CurvedPipeRadius}}
     \pgfcoordinate{lastdown-\number\value{icoord}}{\pgfpoint{\CurvedPipeStep}{-1*\CurvedPipeRadius}}
     \pgfcoordinate{tmpup}{\pgfpoint{\CurvedPipeStep+0.3pt}{\CurvedPipeRadius}}
     \pgfcoordinate{tmpdown}{\pgfpoint{\CurvedPipeStep+0.3pt}{-1*\CurvedPipeRadius}}
     \pgfmathsetmacro\myshadingangle{0}%
     \path[curved pipe/shade,shading angle=\myshadingangle] 
        (lastup-\the\numexpr\value{icoord}-1) 
     -- (tmpup) to[out=180,in=180] (tmpdown) -- (lastdown-\the\numexpr\value{icoord}-1)
     to[out=180,in=180] cycle;%
     \pgfmoveto{\pgfpointanchor{lastup-\the\numexpr\value{icoord}-1}{center}}%
     \pgfpathlineto{\pgfpointanchor{lastup-\number\value{icoord}}{center}}%
     \pgfmoveto{\pgfpointanchor{lastdown-\the\numexpr\value{icoord}-1}{center}}%
     \pgfpathlineto{\pgfpointanchor{lastdown-\number\value{icoord}}{center}}%
  }
  \state{final}[width=\CurvedPipeStep]
  { % perhaps unnecessary but doesn't hurt either
    \pgfmoveto{\pgfpointdecoratedpathlast}
    \fill (tmpup) to[out=0,in=0] (tmpdown) to[out=-180,in=-180] cycle;
  }
}

\begin{document}
  \begin{tikzpicture}
    \draw[decorate,decoration=curved pipe,curved pipe/radius=3mm,looseness=0.7] 
     (0,0) to[bend right] (8,3);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

或者不使用管道字符,只使用阴影

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations} 
\newcounter{icoord}
\pgfkeys{/tikz/.cd,
    curved and shaded/.cd,
    radius/.store in=\CurvedPipeRadius,
    radius=10pt,
    step/.store in=\CurvedPipeStep,
    step=1pt,
    shade/.style={left color=gray,right color=gray,middle color=white}
}

\pgfdeclaredecoration{curved and shaded}{initial}
{% 
\state{initial}[width=\CurvedPipeStep,next state=cont] {%
    \pgfmoveto{\pgfpoint{\CurvedPipeStep}{\CurvedPipeRadius}}%
    \pgfpathlineto{\pgfpoint{0.3\pgflinewidth}{\CurvedPipeRadius}}%
    \setcounter{icoord}{0}%
    \pgfcoordinate{lastup-\number\value{icoord}}{\pgfpoint{1pt}{\CurvedPipeRadius}}%
    \pgfcoordinate{lastdown-\number\value{icoord}}{\pgfpoint{1pt}{-1*\CurvedPipeRadius}}%
  }
  \state{cont}[width=\CurvedPipeStep]{%
     \stepcounter{icoord}%
    \pgfcoordinate{lastup-\number\value{icoord}}{\pgfpoint{\CurvedPipeStep}{\CurvedPipeRadius}}
     \pgfcoordinate{lastdown-\number\value{icoord}}{\pgfpoint{\CurvedPipeStep}{-1*\CurvedPipeRadius}}
     \pgfcoordinate{tmpup}{\pgfpoint{\CurvedPipeStep+0.3pt}{\CurvedPipeRadius}}
     \pgfcoordinate{tmpdown}{\pgfpoint{\CurvedPipeStep+0.3pt}{-1*\CurvedPipeRadius}}
     \pgfmathsetmacro\myshadingangle{0}%
     \path[curved and shaded/shade,shading angle=\myshadingangle] 
        (lastup-\the\numexpr\value{icoord}-1) 
     -- (tmpup) -- (tmpdown) -- (lastdown-\the\numexpr\value{icoord}-1)
     -- cycle;%
     \pgfmoveto{\pgfpointanchor{lastup-\the\numexpr\value{icoord}-1}{center}}%
     \pgfpathlineto{\pgfpointanchor{lastup-\number\value{icoord}}{center}}%
     \pgfmoveto{\pgfpointanchor{lastdown-\the\numexpr\value{icoord}-1}{center}}%
     \pgfpathlineto{\pgfpointanchor{lastdown-\number\value{icoord}}{center}}%
  }
  \state{final}[width=\CurvedPipeStep]
  { % perhaps unnecessary but doesn't hurt either
    \pgfmoveto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
  \begin{tikzpicture}
   \draw[decorate,decoration=curved and shaded,curved and shaded/radius=3mm] 
     (0,0) to[bend right] (8,3);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

这是另一个提议,全部功劳归于 Paul Gaborit这个帖子。我修改了一些内容,并在 pgf 键中存储了一些参数:n是递归次数,f是当前线宽与前一个线宽的比率,color是覆盖层的颜色和opacity不透明度。但从概念上讲,这实际上只是 Paul Gaborit 的想法:用不同的颜色重做路径,而不是完全不透明几次,同时减小线宽。

\documentclass[tikz,border=3mm]{standalone}
\tikzset{% very much based on https://tex.stackexchange.com/a/80207/194703
  pipe beam action/.style={
    line width=\pgfkeysvalueof{/tikz/pipe/f}*\pgflinewidth,
    draw=\pgfkeysvalueof{/tikz/pipe/color},
  },
  pipe beam recurs/.code={%
    \pgfmathtruncatemacro{\level}{#1-1}%
    \ifnum\level=0%
    \tikzset{postaction={pipe beam action}}%
    \else
    \tikzset{postaction={pipe beam action,pipe beam recurs={\level}}}%
    \fi
  },
  pipe beam/.style={pipe/.cd,#1,/tikz/.cd,
  preaction={draw opacity=1,draw/.expanded=\pgfkeysvalueof{/tikz/pipe/color}},
  postaction={draw opacity=\pgfkeysvalueof{/tikz/pipe/opacity},
  pipe beam recurs={\pgfkeysvalueof{/tikz/pipe/n}}}},
  pipe/.cd,n/.initial=10,color/.initial=white,f/.initial=0.95,
  opacity/.initial=0.1
}
\begin{document}
\begin{tikzpicture}
 \path[draw=black,line width=5pt,pipe beam] 
    (-2,0) to[bend right] (2,2);
 \path[draw=black,line width=5pt,pipe beam={n=25,f=0.96}] 
    (-2,-1) to[bend right] (2,1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

欢迎来到TeX.SE.

此建议仅适用于阴影矩形:

\documentclass{book}
\usepackage[prologue]{xcolor}%
\RequirePackage{pstricks}%
\input pst-grad%

\begin{document}

\psframebox[linewidth=0pt,linecolor=white,fillstyle=gradient,gradbegin=black!20,gradend=black!5,gradmidpoint=90]
{\vbox
to 5pc{\vfill\hbox to 12pc{\hfill}\vfill}}


\end{document}

输出

在此处输入图片描述

相关内容