[Tex/LaTex] How to pimp the tube

pgf-decorationsshadingtikz-pgf

How can I pimp my tube?

enter image description here

\documentclass{scrartcl}
% needs logicpuzzle bundle v1.8
% http://mirrors.ctan.org/graphics/pgf/contrib/logicpuzzle/logicpuzzle.sty
% or replace logicpuzzle -> battleship
\usepackage{logicpuzzle}
\makeatletter
\definecolor{LPlgrey}{rgb}{.8,.8,.8}
\definecolor{LPtgrey}{rgb}{.7,.7,.7}
\definecolor{LPgrey}{rgb}{.5,.5,.5}
\def\myscale{.7}
\newcommand*\LPtunnel%
{%
  \begin{tikzpicture}[scale=\myscale]
    \fill[color=black] (0,0) -- (0,1) -- (.4,.5) -- (.4,0) -- cycle;
    \fill[color=LPgrey] (0,1) -- (1,1) -- (1,.5) -- (.4,.5) -- cycle;
    \fill[color=LPlgrey] (.40,0) rectangle (1,.5);
  \end{tikzpicture}
}%
\newcommand*\tunnel[2]{\LP@setcellcontent{#1}{#2}{\LPtunnel}}
\newcommand*\tube[3]%
{%
  \def\tubepath{%
  (#1.5,#2.5)
  \foreach \dir in {#3}%
  {%
    \ifnum\dir=2%
    --++(0,-1)%
    \fi%
    \ifnum\dir=4%
    --++(-1,0)%
    \fi%
    \ifnum\dir=6%
    --++(1,0)%
    \fi%
    \ifnum\dir=8%
    --++(0,1)%
    \fi%
  };}%
  \begin{puzzlebackground}
    \pgfsetcornersarced{\pgfpoint{3mm}{3mm}}
    \draw[color=LPtgrey, line width=.4cm*\myscale] \tubepath;%
  \end{puzzlebackground}
}%
\makeatother
\begin{document}
  \begin{logicpuzzle}[scale=\myscale]
    \tunnel{1}{1}
    \tunnel{5}{5}
    \tube{1}{1}{6,6,6,6,8,8,8,4,2,4,4,4,8,8,6,6,6,6}
  \end{logicpuzzle}
\end{document}

Can I add a decoration like in this picture?

I know I can add a shading (kind of 3D effect) to a rectangle. But it is also possible for such a complex path with a shading based on the angle?

Another important point: It must survive scaling.

Best Answer

Something like that ?

\documentclass{standalone}
% needs logicpuzzle bundle v1.8
% http://mirrors.ctan.org/graphics/pgf/contrib/logicpuzzle/logicpuzzle.sty
% or replace logicpuzzle -> battleship
\usepackage{logicpuzzle}
\makeatletter
\definecolor{LPlgrey}{rgb}{.8,.8,.8}
\definecolor{LPtgrey}{rgb}{.7,.7,.7}
\definecolor{LPgrey}{rgb}{.5,.5,.5}
\def\myscale{.7}
\newcommand*\LPtunnel%
{%
  \begin{tikzpicture}[scale=\myscale]
    \fill[color=black] (0,0) -- (0,1) -- (.4,.5) -- (.4,0) -- cycle;
    \fill[color=LPgrey] (0,1) -- (1,1) -- (1,.5) -- (.4,.5) -- cycle;
    \fill[color=LPlgrey] (.40,0) rectangle (1,.5);
  \end{tikzpicture}
}%
\newcommand*\tunnel[2]{\LP@setcellcontent{#1}{#2}{\LPtunnel}}
\newcommand*\tube[3]%
{%
  \def\tubepath{%
  (#1.5,#2.5)
  \foreach \dir in {#3}%
  {%
    \ifnum\dir=2%
    --++(0,-1)%
    \fi%
    \ifnum\dir=4%
    --++(-1,0)%
    \fi%
    \ifnum\dir=6%
    --++(1,0)%
    \fi%
    \ifnum\dir=8%
    --++(0,1)%
    \fi%
  };}%
  \begin{puzzlebackground}
    \pgfsetcornersarced{\pgfpoint{3mm}{3mm}}
    \draw[color=LPtgrey!80!black, line width=.4cm*\myscale] \tubepath;%
    \draw[color=LPtgrey, line width=.38cm*\myscale] \tubepath;%
    \draw[color=LPtgrey!85, line width=.35cm*\myscale] \tubepath;%
    \draw[color=LPtgrey!70, line width=.32cm*\myscale] \tubepath;%
    \draw[color=LPtgrey!55, line width=.29cm*\myscale] \tubepath;%
    \draw[color=LPtgrey!45, line width=.25cm*\myscale] \tubepath;%
    \draw[color=LPtgrey!35, line width=.2cm*\myscale] \tubepath;%
  \end{puzzlebackground}
}%
\makeatother
\begin{document}
  \begin{tikzpicture}[scale=\myscale]
    \path[draw] (1,1) grid (6,6);
    \tunnel{1}{1}
    \tunnel{5}{5}
    \tube{1}{1}{6,6,6,6,8,8,8,4,2,4,4,4,8,8,6,6,6,6}
  \end{tikzpicture}
\end{document}

enter image description here

Related Question