%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Plain-Tex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%
%% pst-ghsb.tex --- For the PSTricks HSB mode gradient fillstyle
%%                  Based on pst-grad.tex from Timothy van Zandt
%%
%%                  Take care that Hue value is cyclic, so 1=0 !
%%
%% Author          : Denis GIROU (CNRS/IDRIS - France) <Denis.Girou@idris.fr>
%% Created the     : Tue May 13 11:12:36 1997
%% Last mod. by    : Denis GIROU (CNRS/IDRIS - France) <Denis.Girou@idris.fr>
%% Last mod. the   : Thu Jan 29 17:20:13 1998
%% Last mod. by    : Herert Voss <voss _at_ pstricks.de>
%% Last mod. the   : June 06 2004
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\fileversion{1.2}
\def\filedate{2004/06/23}

%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%
%% This defines a new fill style, "gradient", for use with PSTricks,
%% which has gradiated color. The following parameters are used:
%%
%%    gradbegin=color    : Beginning color.
%%    gradend=color      : Final color.
%%    gradlines=int      : Number of lines to use. The higher the number,
%%                           the slower the rendering.
%%    gradmidpoint=num   : Gradient color goes from gradbegin to gradend,
%%                           and then back to beginning. Midpoint (point
%%                           where "gradend" color appears, is gradmidpoint
%%                           from the top.  (0 <= Gmidpoint <= 1).
%%    gradangle=angle    : Rotate image by angle.
%%    GradientCircle=true : Instead of a linear a circled gradient is build.
%%                          (version 1.04)
%%    GradientPos=(x,y) :   the center of the circled gradient
%%                          (version 1.04)
%%    GradientScale=float : scaling factor of the circled gradient
%%                          (version 1.04)
%%

\message{ v\fileversion, \filedate}

\csname GradientHSBLoaded\endcsname
\let\GradientHSBLoaded\endinput

\ifx\PSTricksLoaded\endinput\else
  \def\next{\input pstricks.tex }\expandafter\next
\fi

\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11

\pstheader{pst-ghsb.pro}

\newrgbcolor{gradbegin}{0 .1 .95}
\def\psset@gradbegin#1{\pst@getcolor{#1}\psgradbegin}
\psset@gradbegin{gradbegin}

\newrgbcolor{gradend}{0 1 1}
\def\psset@gradend#1{\pst@getcolor{#1}\psgradend}
\psset@gradend{gradend}

\def\psset@gradlines#1{%
  \pst@getint{#1}\psgradlines
  \ifnum\psgradlines<2
    \@pstrickserr{gradlines must be at least 2}\@epha
    \def\psgradlines{2 }%
  \fi}
\psset@gradlines{300}

\def\psset@gradmidpoint#1{\pst@checknum{#1}\psgradmidpoint}
\psset@gradmidpoint{.9}

\def\psset@gradangle#1{\pst@getangle{#1}\psk@gradangle}
\psset@gradangle{0}

% Herbert Voss 2004-06-23
% To define the gradient as linear or as circle
\newif\ifGradientCircle
\def\psset@GradientCircle#1{\@nameuse{GradientCircle#1}}
\psset@GradientCircle{false}

% Position of the center of the gradient
\def\psset@GradientPos#1{\psset@@GradientPos#1}
\def\psset@@GradientPos(#1){\edef\ps@GradientPos{#1}}
\psset@GradientPos{(0,0)}

% Scale factor
\def\psset@GradientScale#1{\edef\ps@GradientScale{#1}}
\psset@GradientScale{1}

\newif\ifgradientHSB
\def\psset@gradientHSB#1{\@nameuse{gradientHSB#1}}
\psset@gradientHSB{false}

\def\psfs@gradient{%
  \ifgradientHSB
    \addto@pscode{%
      gsave
      gsave \pst@usecolor\psgradbegin currenthsbcolor grestore
      gsave \pst@usecolor\psgradend currenthsbcolor grestore
      \psgradlines
      \psgradmidpoint
      \psk@gradangle
%  hv 2004-05-05 begin    fixed a spurious blank
      tx@GradientHSBDict begin GradientFillHSB end grestore%
    }%
%    tx@GradientHSBDict begin GradientFillHSB end grestore}
%  hv 2004-05-05 end
  \else%
%    hv 2004-06-25 begin    fixed a spurious blank
    \pst@getcoor{\ps@GradientPos}{\pst@tempa}% <- "%"  hv 2004-06-23 
%    hv end
    \addto@pscode{%
      gsave
      \ifGradientCircle true \else false \fi
      \ps@GradientScale\space
      \pst@tempa\space
      gsave \pst@usecolor\psgradbegin currentrgbcolor grestore
      gsave \pst@usecolor\psgradend currentrgbcolor grestore
      \psgradlines
      \psgradmidpoint
      \psk@gradangle
      tx@GradientDict begin GradientFill end grestore%
    }%
  \fi%
}

\catcode`\@=\TheAtCode\relax
\endinput
%% END pst-ghsb.tex
