Subject: Re: [pstricks] Gouraud shading

Herbert Voss LaTeX at zedat.fu-berlin.de
Sun May 29 10:33:46 CEST 2005


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

\pstriangleA(center of the baseline)(width,height){coloraA}{...

Herbert


\documentclass[12pt]{article}
\usepackage{pstricks}
\makeatletter
\def\pstriangleA{\pst at object{pstriangleA}}
\def\pstriangleA at i(#1)(#2)#3#4#5{%
   \begin at ClosedObj
   \pst at getcoor{#1}\pst at tempa%   the center of the baseline
   \pst at getcoor{#2}\pst at tempb%   the width and height of the triangle
   \addto at pscode{%
     /colorA { #3 } def
     /colorB { #4 } def
     /colorC { #5 } def
     \psk at dimen              %   outer/inner/middle
     \pst at tempb
     \psk at gangle             %   rotating angle
     \pst at tempa
     \tx at TriangleA
   }%
   \def\pst at linetype{2}%
   \end at ClosedObj}
\def\psllangle{<< }
\def\psrrangle{>> }
\pst at def{TriangleA}<{
   /mtrx CM def
   translate		% \pst at tempa
   rotate		% \psk at gangle
   /h ED			%
   2 div /w ED		% w: the half width
   dup CLW mul /d ED	% dimen*CLW
   /h h d w h Atan sin Div sub def
   /w w d h w Atan 2 div dup cos exch sin Div mul sub def
   /ds [
      0 w neg d colorA
      0 0 h     colorB
      0 w d     colorC
   ] def
   newpath
   \psllangle
   /ShadingType 4
   /ColorSpace [ /DeviceRGB ]
   /DataSource ds
   \psrrangle
   shfill
   closepath
   mtrx
   setmatrix
}>
\makeatother

\begin{document}

\begin{pspicture}(10,10)
   \pstriangleA(5,0)(10,10){1 0 0}{0 1 0}{0 0 1}
\end{pspicture}

\begin{pspicture}(10,10)
   \pstriangleA(5,0)(10,10){0 0 0}{1 0 0}{1 1 1}
\end{pspicture}

\end{document}




More information about the PSTricks mailing list