# Color gradient filling along a path

I want to make the gradient color to follow the pipe curve below rather than to span from the left to the right.

The following MWE shows the default behavior which is not what I'm looking for.

\documentclass[pstricks,border=12pt]{standalone}

\usepackage{pst-slpe}

\begin{document}

\begin{pspicture}(8,-7)
\pscustom[fillstyle=slope]{
\psline(6,0)
\psarcn(6,-2){2}{90}{-90}
\psline(2,-4)
\psarc(2,-5){1}{90}{-90}
\psline(8,-6)
\psline(8,-7)(2,-7)
\psarcn(2,-5){2}{-90}{90}
\psline(6,-3)
\psarc(6,-2){1}{-90}{90}
\psline(0,-1)
\closepath}
\end{pspicture}

\end{document}


Could you help me to accomplish my objective?

Update

Using Pierre's solution, here is what I ended up with:

\documentclass{article}

\usepackage{pst-plot}

\makeatletter
\define@key[psset]{pst-HSB}{HueBegin}{%
\def\PstParametricplotHSB@HueBegin{#1}}
\define@key[psset]{pst-HSB}{HueEnd}{%
\def\PstParametricplotHSB@HueEnd{#1}}
\define@boolkey[psset]{pst-HSB}[Pst@]{HSB}[true]{}
% Default values
\psset[pst-HSB]{HueBegin = 0, HueEnd = 1, HSB = true}
\psset{dimen = outer}

\def\parametricplotHSB{\pst@object{parametricplotHSB}}
\def\parametricplotHSB@i#1#2#3{{%
\begin@ClosedObj
/t #1 def
/dt #2 t sub \psk@plotpoints\space div def
/t t dt sub def
/Counter 0 def
1 setlinejoin
\psk@plotpoints {
#3
\pst@number\psyunit mul exch
\pst@number\psxunit mul exch
1 Counter eq { moveto currentpoint /OldY ED /OldX ED }
{\ifPst@HSB
/PointY exch def
/PointX exch def
Counter \psk@plotpoints\space div
\PstParametricplotHSB@HueEnd\space
\PstParametricplotHSB@HueBegin\space sub mul
1 1 sethsbcolor
OldX OldY PointX PointY lineto lineto
stroke
PointX PointY moveto
/OldX PointX def /OldY PointY def
\else lineto \fi } ifelse
} repeat }%
\end@ClosedObj}
\ignorespaces}
\makeatother

\begin{document}

\begin{pspicture}(-0.5,-0.5)(4.5,4.5)
\psset{
linewidth = 1cm,
plotpoints = 300
}
\parametricplotHSB[
HueBegin = 0.70,
HueEnd   = 0.66
]{3.05}{0}{t 4}
\parametricplotHSB[
HueBegin = 0.70,
HueEnd   = 0.78
\parametricplotHSB[
HueBegin = 0.78,
HueEnd   = 0.86
]{3.05}{0.95}{t 2}
\parametricplotHSB[
HueBegin = 0.86,
HueEnd   = 0.92
\parametricplotHSB[
HueBegin = 0.92,
HueEnd   = 1
]{0.95}{4}{t 0}
\end{pspicture}

\end{document}


-
@StiffJokes I don't think so (but maybe I'm using it in the wrong place). If this problem is solved, I still can't figure out how to get a smooth colour gradient throughout the entire pipe (with slopebegin = {rgb:orange,0;black,100}, slopeend = {rgb:orange,80;black,20},). –  Svend Tveskæg Dec 22 '13 at 9:08
@StiffJokes Yes. The black end should have the colour {rgb:orange,0;black,100} (i.e., black, as it is now) and the other end (where the pipe is coming out of the furnace and the lower right part of it) should have the colour {rgb:orange,80;black,20}. –  Svend Tveskæg Dec 22 '13 at 9:15
@StiffJokes I have come to the same conclusion. :) –  Svend Tveskæg Dec 22 '13 at 9:20
@SvendTveskæg: draw a line instead of rectangles, use the optional argument of linearc and have a look at tug.org/PSTricks/main.cgi?file=Examples/Colors/colors#contColor –  Herbert Dec 22 '13 at 9:41
@Herbert I have now looked at the examples on the PSTricks page and I can't really figure out how to use it. Can I make you give an answer? –  Svend Tveskæg Dec 22 '13 at 14:48

• I have drawn 3 lines and 2 half-circles (instead of a shape)
• I've used the \parametricplotHSB to have the gradient

and here's what I got :

    \documentclass[xcolor]{article}
\usepackage[utf8]{inputenc}
\usepackage{pstricks,pst-plot,pst-xkey}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Essai de Manuel Luque 19 février 2003
% transformé par Denis Girou le 25 février 2003
% révisé le 9 mai 2007
% modifié par Pierre Vivegnis le 2 juin 2014
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter

\define@key[psset]{pst-plothsb}{HueBegin}{% Between 0 and 1
\edef\PstParametricplotHSB@HueBegin{#1}}

\define@key[psset]{pst-plothsb}{HueEnd}{% Between 0 and 1
\edef\PstParametricplotHSB@HueEnd{#1}}

\newif\ifPst@HSB
\define@key[psset]{pst-plothsb}{HSB}[true]{\@nameuse{Pst@HSB#1}}

% Default values
\psset{HueBegin=0,HueEnd=1,HSB=true}

\def\parametricplotHSB{\pst@object{parametricplotHSB}}
\def\parametricplotHSB@i{\@ifnextchar[{\parametricplotHSB@do}{\parametricplotHSB@do[]}}
\def\parametricplotHSB@do[#1]#2#3#4{{%
\psset{#1}%
\begin@ClosedObj
/t  #2 def
/dt #3 t sub \psk@plotpoints\space div def
/t t dt sub def
/Counter 0 def
\psk@plotpoints {
/F@pstplot \ifPst@algebraic (#4)
tx@AlgToPs begin AlgToPs end cvx
\else { #4 }
\fi
def
\ifPst@algebraic
F@pstplot
\else  #4
\fi
\pst@number\psyunit mul exch
\pst@number\psxunit mul exch
1 Counter eq
{moveto}                    % First point
{\ifPst@HSB                 % Other points than the first one
/PointY exch def
/PointX exch def
Counter \psk@plotpoints\space div
\PstParametricplotHSB@HueEnd\space
\PstParametricplotHSB@HueBegin\space sub mul
1 1 sethsbcolor
PointX PointY lineto
stroke
PointX PointY moveto
\else
lineto
\fi} ifelse
} repeat}% fin du code ps
\end@ClosedObj}} % fin de la commande PSTricks

\makeatother

\begin{document}
\begin{pspicture}[showgrid](-1, -1)(5,5)
\psset{plotpoints=360, linewidth=10mm}%, HSB=false}%
\parametricplotHSB[HueBegin=0,HueEnd=0.2]{-0.5}{3.01}{t 4}
\parametricplotHSB[HueBegin=1,HueEnd=0.8]{4.5}{0.99}{t 0}
\parametricplotHSB[HueBegin=0.4,HueEnd=0.6]{3}{0.95}{t 2}
\end{pspicture}
\end{document}


and I gives me that :

But I can't figure out how, when you add, the HSB=false option, manage the colours...

I hope my answer doesn't come too late... After 6 months :P

## plotpoints

I tried increasing the number of plotted points, but this was the best... For that I can't help you, sorry...

-
This looks very nice! I'm gonna take a look at it later today. Thank you very much. –  Svend Tveskæg Jun 1 at 4:45
A good idea: Create a fully compilable example. Then others will find it easier to use the code when they search the page. –  Svend Tveskæg Jun 2 at 0:11
An extra question: How do I get vertical ends and surround the path with a black curve as in the initial example? –  Svend Tveskæg Jun 4 at 6:31
I have a solution, but it's not quite accurate... Invert the begining and the end of the 2 horizontal lines (and thus the HueBegin and the HueEnd... But it's a crappy way, I'm sure there is a better way... Sorry... –  Pierre Jun 4 at 8:12
See my edited answer... –  Pierre Jun 4 at 13:28