extending pst-gradient

Denis Girou Denis.Girou at idris.fr
Fri Apr 10 19:32:31 CEST 1998


-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

>>>>> "Gerges.Mariano" == MARIANO Georges <mariano at terre.inrets.fr> writes:

    Gerges.Mariano> I need to extend pst-gradient to allow "circle gradient"

  Yesterday evening, I built an user interface to my old PostScript hack to
allow gradients with a circle form. I just finish to clean it up.

  Usage is straightforward. Parameters are GradientCircle, GradientPos and
GradientScale. See the following examples.

  P.S. I also add minor tick marks (normal or logarithmic) to \psaxes. But it
must be validate first.

D.G.

\documentclass{minimal}

\usepackage{pst-grad}

\makeatletter

% D.G. - April 1998

% To define the gradient as linear or as circle
\newif\ifGradientCircle
\def\psset at GradientCircle#1{\@nameuse{GradientCircle#1}}
\psset at GradientCircle{false}

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

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

\def\psfs at gradient{%
% D.G. modification begin - Apr.  9, 1998
%\addto at pscode{gsave
\pst at getcoor{\ps at GradientPos}{\pst at tempa}
\addto at pscode{gsave
    \ifGradientCircle true \else false \fi
    \ps at GradientScale\space
    \pst at tempa
% D.G. modification end
    gsave \pst at usecolor\psgradbegin currentrgbcolor grestore
    gsave \pst at usecolor\psgradend currentrgbcolor grestore
    \psgradlines
    \psgradmidpoint
    \psk at gradangle
    tx at GradientDict begin GradientFill end grestore}}

\makeatother

\begin{document}

\psset{linestyle=none,fillstyle=gradient,gradmidpoint=0,gradend=white}

\psset{gradbegin=red}
\begin{pspicture}(-2,-2)(2,2)
  \pscircle{2}
\end{pspicture}
\psset{GradientCircle=true}
\begin{pspicture}(-2,-2)(2,2)
  \pscircle{2}
\end{pspicture}
\begin{pspicture}(-2,-2)(2,2)
  \pscircle[GradientPos={(2,1)}]{2}
\end{pspicture}

\psset{gradbegin=green}
\begin{pspicture}(4,3)
  \psframe(4,2)
\end{pspicture}
\begin{pspicture}(4,3)
  \psframe[GradientPos={(2,1)}](4,2)
\end{pspicture}
\begin{pspicture}(4,3)
  \psframe[GradientPos={(3.5,1.5)}](4,2)
\end{pspicture}

\begin{pspicture}(4,3)
  \psframe(4,2)
\end{pspicture}
\begin{pspicture}(4,3)
  \psframe[GradientScale=3](4,2)
\end{pspicture}
\begin{pspicture}(4,3)
  \psframe[GradientScale=6](4,2)
\end{pspicture}

\psset{gradbegin=cyan}
\begin{pspicture}(2,-1)(6,2)
  \psframe(2,-1)(6,1)
\end{pspicture}
\begin{pspicture}(2,-1)(6,2)
  \psframe[gradmidpoint=0.5,GradientPos={(2.5,0.5)}](2,-1)(6,1)
\end{pspicture}
\begin{pspicture}(2,-1)(6,2)
  \psframe[gradmidpoint=1,GradientPos={(4,1)}](2,-1)(6,1)
\end{pspicture}

\begin{pspicture}(-2.5,-1.25)(2.5,1.25)
  \psellipse[gradbegin=blue,GradientScale=2](2.5,1.25)
\end{pspicture}
\begin{pspicture}(3,4)
  \pspolygon[gradbegin=black](0,0)(1,3)(3,2)(1.5,2)(2,0.5)
\end{pspicture}
\begin{pspicture}(3,4)
  \psdiamond[gradbegin=magenta,gradend=yellow](1.5,1)(1.5,1)
\end{pspicture}

\end{document}

------------------------------------------------------------------------------

%!
% PostScript prologue for pst-grad.tex.
% Version 97.1, 98/04/09 (adding GradientCircle style - D.G.)
% For copying restrictions, see pstricks.tex.
%
% For the PSTricks gradient fillstyle.
%
% Based on some EPS files by leeweyr!bill at nuchat.sccsi.com (W. R. Lee).
%
% Syntax:
% D.G. modification begin - Apr.  9, 1998
%%%%%% R0 G0 B0 R1 G1 B1 NumLines MidPoint Angle GradientFill
%   ifGradientCircle GradientScale GradientPosX GradientPosY
%     R0 G0 B0 R1 G1 B1 NumLines MidPoint Angle GradientFill
% D.G. modification end

/tx at GradientDict 40 dict def
tx at GradientDict begin
/GradientFill {
  rotate
  /MidPoint ED
  /NumLines ED
  /LastBlue ED
  /LastGreen ED
  /LastRed ED
  /FirstBlue ED
  /FirstGreen ED
  /FirstRed ED
% D.G. modification begin - Apr.  9, 1998
  /GradientPosY ED
  /GradientPosX ED
  /GradientScale ED
  /ifGradientCircle ED
% D.G. modification end
  % This avoids gaps due to rounding errors:
  clip
  pathbbox           %leave llx,lly,urx,ury on stack
% D.G. modification begin - Apr. 10, 1998
  4 copy /ury ED /urx ED /lly ED /llx ED
% D.G. modification end
  /y ED /x ED
% D.G. modification begin - Apr. 10, 1998
  ifGradientCircle
   {0 GradientPosX eq {0 GradientPosX eq {2 copy translate} if} if}
   {2 copy translate} ifelse
% D.G. modification end
  y sub neg /y ED
  x sub neg /x ED
  % This avoids gaps due to rounding errors:
  LastRed FirstRed add 2 div
  LastGreen FirstGreen add 2 div
  LastBlue FirstBlue add 2 div
  setrgbcolor
% D.G. modification begin - Jul. 23, 1997 / Apr.  9, 1998
  ifGradientCircle
   {/YSizePerLine y NumLines div def
    /CurrentY y 2 div def
    /MidLine NumLines 2 div 1 MidPoint sub mul abs cvi def}
   {fill
    /YSizePerLine y NumLines div def
    /CurrentY 0 def
    /MidLine NumLines 1 MidPoint sub mul abs cvi def} ifelse
% DG modification end
  MidLine NumLines 2 sub gt
  { /MidLine NumLines def }
  { MidLine 2 lt { /MidLine 0 def } if }
  ifelse
  MidLine 0 gt
  {
    /Red FirstRed def
    /Green FirstGreen def
    /Blue FirstBlue def
    /RedIncrement LastRed FirstRed sub MidLine 1 sub div def
    /GreenIncrement LastGreen FirstGreen sub MidLine 1 sub div def
    /BlueIncrement LastBlue FirstBlue sub MidLine 1 sub div def
    MidLine { GradientLoop } repeat
  } if
  MidLine NumLines lt
  {
    /Red LastRed def
    /Green LastGreen def
    /Blue LastBlue def
    /RedIncrement FirstRed LastRed sub NumLines MidLine sub 1 sub div def
    /GreenIncrement FirstGreen LastGreen sub NumLines MidLine sub 1 sub div def
    /BlueIncrement FirstBlue LastBlue sub NumLines MidLine sub 1 sub div def
    NumLines MidLine sub { GradientLoop } repeat
  } if
} def
/GradientLoop {
% D.G. modification begin - Jul. 23, 1997 / Apr.  9, 1998
  ifGradientCircle
   {CurrentY 0 gt {
% The default center used is the center of the bounding box of the object
      0 GradientPosX eq
        {0 GradientPosX eq
           {/GradientPosX urx llx sub 2 div def
            /GradientPosY ury lly sub 2 div def} if} if
      GradientPosX GradientPosY CurrentY GradientScale mul 0 360 arc
      Red Green Blue setrgbcolor fill
      /CurrentY CurrentY YSizePerLine sub def
      /Blue Blue BlueIncrement add def
      /Green Green GreenIncrement add def
      /Red Red RedIncrement add def} if}
   {0 CurrentY moveto
    x 0 rlineto
    0 YSizePerLine rlineto
    x neg 0 rlineto
    closepath
    Red Green Blue setrgbcolor fill
    /CurrentY CurrentY YSizePerLine add def
    /Blue Blue BlueIncrement add def
    /Green Green GreenIncrement add def
    /Red Red RedIncrement add def} ifelse
% D.G. modification end
} def

end
% END pst-grad.pro

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list