I'm drawing pipes (like the Pipeline game), and I want them to be shaded to give the effect that the pipes are cylindrical.
A bit like the pipes below: the outer edges are black, the middle is white (I tried bottom color=black,middle color=white,bottom color=black
but the pipes just showed up as black. Perhaps because I'm getting my pipe width from the line width instead of as a fill? I'm amenable to changing the way the pipes are defined, so long as I can still draw them easily, with the details abstracted away in the pipe style).
(image credit: "Plumber Game")
There are a number of questions (example) that deal with applying a gradient along a path (as in say green on one end of the path, red on the other); but I want the gradient to be perpendicular to that.
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{
pipe/.style = {
draw,
rounded corners,
line width=3mm
}
}
\begin{tikzpicture}
% a pipe.
\draw [pipe] (0, 0) -- (0, 3) -- (1, 3);
\end{tikzpicture}
\end{document}
Update
@Symbol-1's suggestion of pgf-blur leads me to the following: I define the blur colour to be white (the centre colour of the pipe). Since the blur fades to transparent, I draw the solid colour of the pipe underneath, first, with preaction.
However in order for the blur to render appropriately I need to draw my right-angle pipe as two separate line segments, which then don't join smoothly. I can try separately drawing the underlying pipe (smoothly) and then the blur (nonsmoothly) but then you can see the blur doesn't quite meet in the corners (plus it is a small pain to redefine the pipe and shadow twice for each pipe, but I can live with this)::
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}
\makeatletter
\tikzset{
/tikz/render blur shadow/.code={
\pgfbs@savebb
\pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
\pgfbs@compute@shadow@bbox
\pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
\pgfbs@apply@canvas@transform
\colorlet{pstb@shadow@color}{white!\pgfbs@opacity!black}%
\pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
\pgfsetfillcolor{\blurcolor}%
\pgfsetfading{shadowfading}%
{\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
\pgfbs@usebbox{fill}%
\pgfbs@restorebb
}
}
\tikzset{
basepipe/.style = {
rounded corners,
line width=3mm
},
pipe/.style = {
basepipe,
% shadow stuff
blur shadow, shadow xshift=0, shadow yshift=0,
shadow blur radius=1.5mm, shadow opacity=100, shadow blur steps=100,
}
}
\def\blurcolor{white}
\begin{document}
\begin{tikzpicture}
% a pipe.
\path [preaction={draw,basepipe}][pipe] (0, 0) -- (0, 3) -- cycle (0,3) -- (1, 3);
% another pipe, without cycle
\begin{scope}[xshift=1.5cm]
\path [preaction={draw,basepipe}][pipe] (0, 0) -- (0, 3) -- (1, 3);
\end{scope}
% another pipe
\begin{scope}[xshift=3cm]
\draw [basepipe] (0,0) -- (0,3) -- (1,3);
\path [pipe] (0, 0) -- (0, 3) -- cycle (0,3) -- (1, 3);
\end{scope}
\end{tikzpicture}
\end{document}
Can anyone help me get the last step?