Subject: Re: [pstricks] Gouraud shading
Herbert Voss
LaTeX at zedat.fu-berlin.de
Sun May 29 19:03:42 CEST 2005
Herbert Voss wrote:
> Eugene K. Ressler wrote:
>
>> Chapter 14, page 13. Included below. This PS draws a triangle with
>> shading interpolated among red, black, and white. A syntax like the
>> following would be nice
>>
>> \gouraudtriangle[options...](0,.866){1,0,0}(-.5,0){1,1,1}(.5,0){0,0,0}
>
>
> only a first idea ...
and a better one. Uses color setting of xcolor.sty
I asked Uwe, if xcolor can handle rgb values in the same way.
We'll see ...
You can uncomment the forth line in the /ds [
part, then you get the shading for the parallelogram.
Herbert
\documentclass[12pt]{article}
\usepackage{pstricks}
\makeatletter
\def\psGTriangle{\pst at object{psGTriangle}}
\def\psGTriangle at i(#1)(#2)(#3)#4#5#6{{%
\def\solid at star{}
\begin at ClosedObj
\pst at getcoor{#1}\pst at tempa% A: "rgb xr xg xb" or "gray xg"
\pst at getcoor{#2}\pst at tempb% B
\pst at getcoor{#3}\pst at tempc% C
\pst at getcolor{#4}\pst at colorA
\pst at getcolor{#5}\pst at colorB
\pst at getcolor{#6}\pst at colorC
\addto at pscode{%
\pst at tempc % C
\pst at tempb % B
\psk at gangle % rotating angle
\pst at tempa % A, temporary origin
/rgb {} def
/gray {} def
[ \pst at colorC ] aload length 1 eq { dup dup } if 3 array astore %
gray -> rgb
[ \pst at colorB ] aload length 1 eq { dup dup } if 3 array astore
[ \pst at colorA ] aload length 1 eq { dup dup } if 3 array astore
\tx at GTriangle % PS part
}%
\if at star\pspolygon(#1)(#2)(#3)\fi% draw borderline
\def\pst at linetype{2}%
\end at ClosedObj}}
%
\pst at def{GTriangle}<{
/mtrx CM def
/colorA ED /colorB ED /colorC ED % save the colors
/xA ED /yA ED % save the origin
xA yA translate
rotate % \psk at gangle
/yB ED /xB ED /yC ED /xC ED % save other coordinates
/ds [ % save data in a array
0 0 0 colorA aload pop % fd x y xr xg xb
0 xB xA sub yB yA sub colorB aload pop
0 xC xA sub yC yA sub colorC aload pop
% 1 xC xB add yB colorA aload pop % for use with 4 points ABCD
] def
newpath
<<
/ShadingType 4 % single Gouraud
/ColorSpace [ /DeviceRGB ]
/DataSource ds
>>
shfill
closepath
mtrx
setmatrix
}>
\makeatother
\begin{document}
\begin{pspicture}(10,10)
\psGTriangle(0,0)(5,10)(10,0){red}{green}{blue}
\end{pspicture}
\begin{pspicture}(10,10)
\psGTriangle*(0,0)(9,10)(10,3){black}{white!50}{red!50!green!95}
\end{pspicture}
\begin{pspicture}(10,10)
\psGTriangle*(0,0)(5,10)(10,0){green!16!blue!12}
{red!20!blue!60}
{red!40!green!70}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list