[pstricks] Real transparency hack

MLuque5130 at aol.com MLuque5130 at aol.com
Fri Jul 15 18:15:14 CEST 2005


Hi Jan,

Dans un e-mail daté du 14/07/2005 22:39:38 Paris, Madrid (heure d'été), 
me at jansteffan.de a écrit :

>The benefit of this approach would be that it works with older viewer, too 
>which don't support transparency (new viewers like kpdf don't either).
>The flip side that it only works for simple graphics. You'll never be able
>to layer a transparent surface over a bitmap and dealing with more than two
>or three overlapping shapes in a generic way is probably nontrivial.

I think that for a good programmer knowing PostScript well, there is nothing 
impossible.  It is not my case.  
By doing oneself the decoration with PSTricks, here some examples of 
transparency.  

http://melusine.eu.org/syracuse/mluque/arthurcolors/arthurcolors.html
http://melusine.eu.org/syracuse/mluque/Venise/saint_marc42/saint_marc42.html

Here a particularly effective command written by Denis Girou.


\documentclass{article}

\usepackage{arrayjob}
\usepackage[width=19cm,height=28cm]{geometry}
\usepackage{multido}
%\usepackage{pstcol}
\usepackage{pstricks}
\usepackage{pst-char}
% Manuel Luque
% Denis Girou
\input{random} % Donald Arseneau

\setlength{\parindent}{0pt}

\DeclareFixedFont{\Sf}{T1}{phv}{b}{n}{4cm}
\DeclareFixedFont{\Rm}{T1}{ptm}{m}{n}{4cm}

\newarray\colorCyan
\newarray\colorMagenta
\newarray\colorYellow

\expandarrayelementtrue

\psset{dimen=middle}

\makeatletter

\def\GraphicBackground(#1,#2){%
% #1 = horizontal size, #2 = vertical size
\multido{\iLineMOne=\z at +\@ne,\iLine=\@ne+\@ne}{#1}{%
  \multido{\iColumnMOne=\z at +\@ne,\iColumn=\@ne+\@ne}{#2}{%
    \setrandim{\pst at dima}{\z@}{0.4pt}%
    \global\colorCyan(\iLine,\iColumn)={\pointless\pst at dima}
    \setrandim{\pst at dimb}{\z@}{0.4pt}%
    \global\colorMagenta(\iLine,\iColumn)={\pointless\pst at dimb}
    \setrandim{\pst at dimc}{\z@}{0.4pt}%
    \global\colorYellow(\iLine,\iColumn)={\pointless\pst at dimc}
    \definecolor{MyColor}{cmyk}%
                
{\pointless\pst at dima,\pointless\pst at dimb,\pointless\pst at dimc,0}%
    \psframe[fillstyle=solid,fillcolor=MyColor,linestyle=none]
            (\iLineMOne,\iColumnMOne)(\iLine,\iColumn)}}}

\def\GraphicTransparent(#1,#2,#3)(#4,#5){%
% #1, #2, #3 = cyan, magenta and yellow components of the color filter,
% #4, #5 = horizontal and vertical indices
\multido{\iLineMOne=\z at +\@ne,\iLine=\@ne+\@ne}{#4}{%
  \multido{\iColumnMOne=\z at +\@ne,\iColumn=\@ne+\@ne}{#5}{%
    \checkcolorCyan(\iLine,\iColumn)%
    \pst at dima\cachedata pt
    \advance\pst at dima by #1pt
    \ifdim\pst at dima>\@ne pt\pst at dima=\@ne pt\fi
    \checkcolorMagenta(\iLine,\iColumn)%
    \pst at dimb=\cachedata pt
    \advance\pst at dimb by #2pt
    \ifdim\pst at dimb>\@ne pt\pst at dimb=\@ne pt\fi
    \checkcolorYellow(\iLine,\iColumn)%
    \pst at dimc=\cachedata pt
    \advance\pst at dimc by #3pt
    \ifdim\pst at dimc>\@ne pt\pst at dimc=\@ne pt\fi
    \definecolor{MyColor}{cmyk}%
                
{\pointless\pst at dima,\pointless\pst at dimb,\pointless\pst at dimc,0}%
    \psframe[linestyle=none,fillstyle=solid,fillcolor=MyColor]
            (\iLineMOne,\iColumnMOne)(\iLine,\iColumn)}}}

\def\TextTransparent(#1,#2,#3)(#4,#5)#6{%
% #1, #2, #3 = cyan, magenta and yellow components of the color filter,
% #4, #5 = horizontal and vertical indices,
% #6 = text
\checkcolorCyan(#4,#5)%
\pst at dima\cachedata pt
\advance\pst at dima by #1pt
\ifdim\pst at dima>\@ne pt\pst at dima=\@ne pt\fi
\checkcolorMagenta(#4,#5)%
\pst at dimb=\cachedata pt
\advance\pst at dimb by #2pt
\ifdim\pst at dimb>\@ne pt\pst at dimb=\@ne pt\fi
\checkcolorYellow(#4,#5)%
\pst at dimc=\cachedata pt
\advance\pst at dimc by #3pt
\ifdim\pst at dimc>\@ne pt\pst at dimc=\@ne pt\fi
\definecolor{MyColor}{cmyk}%
            {\pointless\pst at dima,\pointless\pst at dimb,\pointless\pst at dimc,0}%
#6}

\def\TestGraphic(#1,#2,#3)(#4,#5)#6#7{%
% #1, #2, #3 = cyan, magenta and yellow components of the color filter,
% #4 = horizontal size, #5 = vertical size, #6 = random seed, #7 = graphic
\definecolor{ColorFilter}{cmyk}{#1,#2,#3,0}%
\dataheight=#4\relax
\pspicture(#4,#5)
  \psset{linestyle=none,fillstyle=solid,fillcolor=ColorFilter}%
  #7
\endpspicture
\hskip 1cm
\pspicture(#4,#5)
  \randomi=#6\relax
  \GraphicBackground(#4,#5)%
\endpspicture
\hskip 1cm
\pspicture(#4,#5)
  \randomi=#6\relax
  \GraphicBackground(#4,#5)%
  \psclip{\pscustom[linestyle=none]{#7}}
    \GraphicTransparent(#1,#2,#3)(#4,#5)%
  \endpsclip
\endpspicture}

\def\TestText(#1,#2,#3)(#4,#5)#6#7{%
% #1, #2, #3 = cyan, magenta and yellow components of the color filter,
% #4 = horizontal size, #5 = vertical size, #6 = random seed, #7 = text
\definecolor{ColorFilter}{cmyk}{#1,#2,#3,0}%
\dataheight=#4\relax
\pspicture(#4,#5)
  \randomi=#6\relax
  \GraphicBackground(#4,#5)%
\endpspicture
\hskip 1cm
\pspicture(#4,#5)
  \randomi=#6\relax
  \GraphicBackground(#4,#5)%
  \multido{\iLineMOne=\z at +\@ne,\iLine=\@ne+\@ne}{#4}{%
    \multido{\iColumnMOne=\z at +\@ne,\iColumn=\@ne+\@ne}{#5}{%
      \psclip{\psframe[linestyle=none]
                      (\iLineMOne,\iColumnMOne)(\iLine,\iColumn)}
        \TextTransparent(#1,#2,#3)(\iLine,\iColumn)%
          {\rput(0,0){%
             \pscharpath[linestyle=none,
                         fillstyle=solid,fillcolor=MyColor]{#7}}}
      \endpsclip}}
\endpspicture}

\makeatother

\begin{document}

\TestGraphic(0.8,0.1,0.1)(5,5){574214204}{\pscircle(2.5,2.5){1.75}}

\vspace{1cm}
\TestText(0.8,0.1,0.1)(8,6){574214204}{\rput[lb]{37}(2,-0.5){\Sf TeX}}

\vspace{1cm}
\TestGraphic(0,0.5,0.4)(5,5){2568792}{\pscurve(0.5,1)(2.5,4.5)(4.5,2)(2,0.5)}

\vspace{1cm}
\TestText(0.2,0.4,0.2)(9,6){2568792}
         {\rput[lb](0.5,0.5){\scalebox{0.75 1.8}{\Rm LaTeX}}}

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%

Manuel




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/pstricks/attachments/20050715/f5ea736a/attachment.html 


More information about the PSTricks mailing list