[pstricks] mixing colours of overlapping objects while disregarding paper background colour

Juergen Gilg gilg at acrotex.net
Wed Jun 10 15:40:50 CEST 2009


Dear Alexander,

try this:

\makeatletter
% Draw two overlapped surfaces, with computation of the mixed color for
% the intersection of the surfaces
% #1=first  surface, #2=color of first  surface,
% #3=second surface, #4=color of second surface
\def\ColoredOverlappedSurfaces#1#2#3#4{%
  \psset{fillstyle=solid}%
  % Decode the three components of the first RGB color
  \psset{fillcolor=#2}% % Draw first surface
  #1
  % Decode the three components of the second RGB color
  % Draw second surface
  \psclip{\psset{fillcolor=#4}#3}%
  \psset{fillcolor=#2!50!#4}%
  % Redraw overlapped surface in the mixed color
  #1%
  \endpsclip%
}
\makeatother


Regards,

Juergen

Alexander Grahn wrote:
> Hi,
>
> I wish it were possible to mix the colour of overlapping objects but,
> at the same time, to prevent the background colour from being mixed in.
>
> Consider the example below where I have a red (rgb=1 0 0) circle and a
> blue (rgb=0 0 1) ellipse, overlapping each other. It would be extremely
> nice to have the overlapping region to be filled with colour rgb=1 0 1
> and the non-overlapping regions to be filled with fully saturated red
> and blue colours.
>
> Unfortunately, neither black nor white backgrounds give the desired
> result.
>
> Is there a way to achieve this in the final ps2pdf generated PDF?
>
> Thanks for your suggestions!
>
> Regards,
> Alexander
>
> \documentclass{article}
> \usepackage{pstricks}
>
> \def\ColoredOverlappedSurfaces#1#2#3#4{%
>   \psset{fillstyle=solid,opacity=0.5}%
>   \psset{fillcolor=#2}#1
>   \psset{fillcolor=#4}#3}
>
> \pagestyle{empty}
>
> \begin{document}
>
> \psset{unit=2}
> \psframebox*[fillcolor=black,fillstyle=solid]{%
> \begin{pspicture}(-2,-2)(2,2)
> \rput(0,0){%
>   \ColoredOverlappedSurfaces{\pscircle{1}}{red}{\psellipse(0.3,-0.7)(1.5,1)}{blue}}
> \end{pspicture}}
>
> \begin{pspicture}(-2,-2)(2,2)
> \rput(0,0){%
>   \ColoredOverlappedSurfaces{\pscircle{1}}{red}{\psellipse(0.3,-0.7)(1.5,1)}{blue}}
> \end{pspicture}
> \end{document}
> _______________________________________________
> PSTricks mailing list
> PSTricks at tug.org
> http://tug.org/mailman/listinfo/pstricks
>
>
>   

-- 
 Jürgen Gilg
 Austr. 59
 70376 Stuttgart
-------------------------------------
 Tel       0711.59 27 88
 e-Mail    gilg at acrotex.net


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/pstricks/attachments/20090610/7a7ad2e8/attachment.html>


More information about the PSTricks mailing list