Denis Girou Denis.Girou at idris.fr
Wed Jul 23 21:52:49 CEST 1997

-----------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------

>>>>> "Jan.Krupa" == Jan Krupa <krupa at alpha.sggw.waw.pl> writes:

Jan.Krupa> I would like to draw ** a 3D ball filled gradually to achieve the 3D effect**.
Jan.Krupa> How it is possible using PSTricks?

Jan.Krupa> ............................................................

Jan.Krupa> The problem is that 'gradient' macro fills the region gradually but the
Jan.Krupa> lines of "the same intensity of color" are **straight line**.
Jan.Krupa> How is it possible to force the gradient macro to have the lines as e.g.
Jan.Krupa> ellipse or other curve ?

Here is one attempt (not perfect, but is seems usable).

Variations are obtained playing with the lines ". . scale" in the
GradientFill macro and "x . div y . div CurrentY 0 360 arc" in the

D.G.

\documentclass{article}

\pagestyle{empty}

\begin{document}

\pstVerb{%
rotate
/MidPoint ED
/NumLines ED
/LastBlue ED
/LastGreen ED
/LastRed ED
/FirstBlue ED
/FirstGreen ED
/FirstRed ED
% This avoids gaps due to rounding errors:
clip
pathbbox           %leave llx,lly,urx,ury on stack
/y ED /x ED
2 copy translate
y sub neg /y ED
x sub neg /x ED
% This avoids gaps due to rounding errors:
setrgbcolor
% DG modification begin - Jul. 23, 1997
%  fill
%  /YSizePerLine y NumLines div def
%  /CurrentY 0 def
%  /MidLine NumLines 1 MidPoint sub mul abs cvi def
/YSizePerLine y NumLines div def
/CurrentY y 2 div def
/MidLine NumLines 2 div 1 MidPoint sub mul abs cvi def
% 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
} 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
% DG modification begin - Jul. 23, 1997
CurrentY 0 gt {
x 2 div y 2 div CurrentY 0 360 arc
Red Green Blue setrgbcolor fill
/CurrentY CurrentY YSizePerLine sub def
} if
% DG modification end
} def
end}

\pstVerb{%
% DG modification begin - Jul. 23, 1997
CurrentY 0 gt {
x 1.5 div y 1.5 div CurrentY 0 360 arc
Red Green Blue setrgbcolor fill
/CurrentY CurrentY YSizePerLine sub def
} if
% DG modification end
} def
end}

\vspace{5cm}

\vspace{5cm}

\pstVerb{%
rotate
/MidPoint ED
/NumLines ED
/LastBlue ED
/LastGreen ED
/LastRed ED
/FirstBlue ED
/FirstGreen ED
/FirstRed ED
% This avoids gaps due to rounding errors:
clip
pathbbox           %leave llx,lly,urx,ury on stack
/y ED /x ED
2 copy translate
y sub neg /y ED
x sub neg /x ED
% This avoids gaps due to rounding errors:
setrgbcolor
% DG modification begin - Jul. 23, 1997
%  fill
%  /YSizePerLine y NumLines div def
%  /CurrentY 0 def
%  /MidLine NumLines 1 MidPoint sub mul abs cvi def
/YSizePerLine y NumLines div def
/CurrentY y 2 div def
/MidLine NumLines 2 div 1 MidPoint sub mul abs cvi def
% 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
% DG modification begin - Jul. 23, 1997
2 1 scale
% DG modification end
} 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
% DG modification begin - Jul. 23, 1997
CurrentY 0 gt {
x 4 div y 2 div CurrentY 0 360 arc
Red Green Blue setrgbcolor fill
/CurrentY CurrentY YSizePerLine sub def
} if
% DG modification end
} def
end}

\vspace{5cm}

\end{document}

-----------------------------------------------------------------------------
To [un]subscribe to this list, send mail to pstricks-request at mail.tug.org
Leave the subject line blank and in the body put the line