来自 pstricks 手册 (p223) 的高级宏,它不起作用

来自 pstricks 手册 (p223) 的高级宏,它不起作用
\documentclass{article}
\usepackage{pstricks}

\makeatletter
% We draw the first surface #1 clipped by the one
% or two others #2 and #3, computing it resulting color
\def\PstColorSynthesis@ClippedSurfaces#1#2#3{%
% We compute the “mixed” color, component by component
\def\PstColorSynthesis@MixedColorR{0}%
\def\PstColorSynthesis@MixedColorG{0}%
\def\PstColorSynthesis@MixedColorB{0}%
% \pst@dimd will contain the maximum value of the three
% components.
 \pst@dimd=\z@
 \PstColorSynthesis@MixedColor{%
 \csname PstColorSynthesis@Color#1\endcsname}%
 \PstColorSynthesis@MixedColor{%
 \csname PstColorSynthesis@Color#2\endcsname}%
 \PstColorSynthesis@MixedColor{%
 \csname PstColorSynthesis@Color#3\endcsname}%
 % We must test if the maximum of the new computed
 % component is greater than 1, in which case we divide all
 % the three components by this value for additive synthesis.
 \ifdim\pst@dimd>\@ne\p@
   \PstColorSynthesis@MixedColor@iii{\PstColorSynthesis@MixedColorR}%
   \PstColorSynthesis@MixedColor@iii{\PstColorSynthesis@MixedColorG}%
   \PstColorSynthesis@MixedColor@iii{\PstColorSynthesis@MixedColorB}%
 \fi
 % We draw the first surface, clipped by the other ones
 \psclip{\csname PstColorSynthesis@Surface#2\endcsname%
 \csname PstColorSynthesis@Surface#3\endcsname}
 \definecolor{MixedColor}{rgb}{\PstColorSynthesis@MixedColorR,
   \PstColorSynthesis@MixedColorG,
   \PstColorSynthesis@MixedColorB}%
 \psset{fillstyle=solid,fillcolor=MixedColor}%
 \csname PstColorSynthesis@Surface#1\endcsname
 \endpsclip}

 \def\PstColorSynthesis@MixedColor@i#1 #2 #3 #4\@nil{%
 % We receive the name of the color model (“rgb” is expected
 % here and the three color components.)
 % We add the values to the respective components of the new
 % color to compute.
 \PstColorSynthesis@MixedColor@ii{%
 \PstColorSynthesis@MixedColorR}{#2}%
 \PstColorSynthesis@MixedColor@ii{%
 \PstColorSynthesis@MixedColorG}{#3}%
 \PstColorSynthesis@MixedColor@ii{%
 \PstColorSynthesis@MixedColorB}{#4}}

 \def\PstColorSynthesis@MixedColor@ii#1#2{%
 % As these values are real numbers, we use dimension
 % registers, then we assign the computed value in a macro,
 % converting it from a dimension to a number.
 % We also keep in \pst@dimd the maximum of the values.
 \pst@dimg=#1\p@
 \advance\pst@dimg by #2\p@
 \pst@dimtonum{\pst@dimg}{#1}%
 \ifdim\pst@dimg>\pst@dimd
 \pst@dimd=\pst@dimg
 \fi}

 \def\PstColorSynthesis@MixedColor@iii#1{%
 \pst@divide{#1\p@}{\pst@dimd}{#1}%
 % We must take care of possible rounding problems with
 % \pst@divide (for instance, 1.8/1.8 give 1.0001)
 \ifdim#1\p@>\@ne\p@
 \def#1{1}%
 \fi}

 % We redefine Cyan, Magenta and Yellow in the “rgb” model
 \definecolor{Cyan}{rgb}{0,1,1}%
 \definecolor{Magenta}{rgb}{1,0,1}%
 \definecolor{Yellow}{rgb}{1,1,0}%

 \makeatother

\begin{document}

\begin{pspicture}
 \PstColorSynthesis[SurfaceA={\pscircle{2}},
 SurfaceB={\pscircle(2,0){2}},SurfaceC={\pscircle(1,2){2}},
 ColorA=Cyan,ColorB=Magenta,ColorC=Yellow]
 \PstColorSynthesis[SurfaceA={\psccurve(-3,1)(0,2.5)(2,1.5)(4,3)(4,-1)
 (3,0)(1,-2.5)(-1,-1)(-3,-3)},
 SurfaceB={\psellipticarc(0,-1)(3,1.5){41}{-92}},
 SurfaceC={\pstriangle(1,-2)(5,5)},
 ColorA=SlateBlue,ColorB=Orange,ColorC=Pink]
\end{pspicture}
\end{document} 

答案1

我不止一次告诉过你,你应该不是使用\setkeys。PSTricks 的正确宏是\psset

\documentclass{article}
\usepackage{pstricks}
\makeatletter
\define@key[psset]{}{SurfaceA}{\def\PstColorSynthesis@SurfaceA{#1}}
\define@key[psset]{}{SurfaceB}{\def\PstColorSynthesis@SurfaceB{#1}}
\define@key[psset]{}{SurfaceC}{\def\PstColorSynthesis@SurfaceC{#1}}
\define@key[psset]{}{ColorA}{\def\PstColorSynthesis@ColorA{#1}}
\define@key[psset]{}{ColorB}{\def\PstColorSynthesis@ColorB{#1}}
\define@key[psset]{}{ColorC}{\def\PstColorSynthesis@ColorC{#1}}
\def\PstColorSynthesis{\pst@object{PstColorSynthesis}}%
\def\PstColorSynthesis@i{{%
        \psset{linestyle=none}%
        \use@par% Assignment of local parameters
        \bgroup
        \psset{fillstyle=solid,fillcolor=\PstColorSynthesis@ColorA}%
        \PstColorSynthesis@SurfaceA
        \psset{fillcolor=\PstColorSynthesis@ColorB}%
        \PstColorSynthesis@SurfaceB
        \psset{fillcolor=\PstColorSynthesis@ColorC}%
        \PstColorSynthesis@SurfaceC
        \egroup
        \PstColorSynthesis@ClippedSurfaces{A}{B}{NoSurface}%
        \PstColorSynthesis@ClippedSurfaces{A}{C}{NoSurface}%
        \PstColorSynthesis@ClippedSurfaces{B}{C}{NoSurface}%
        \PstColorSynthesis@ClippedSurfaces{A}{B}{C}}}

\def\PstColorSynthesis@ColorNoSurface{}

\def\PstColorSynthesis@ClippedSurfaces#1#2#3{%
    \def\PstColorSynthesis@MixedColorR{0}%
    \def\PstColorSynthesis@MixedColorG{0}%
    \def\PstColorSynthesis@MixedColorB{0}%
    \PstColorSynthesis@MixedColor{\csname PstColorSynthesis@Color#1\endcsname}%
    \PstColorSynthesis@MixedColor{\csname PstColorSynthesis@Color#2\endcsname}%
    \PstColorSynthesis@MixedColor{\csname PstColorSynthesis@Color#3\endcsname}%
    \psclip{\csname PstColorSynthesis@Surface#2\endcsname%
        \csname PstColorSynthesis@Surface#3\endcsname}
    \definecolor{MixedColor}{rgb}{\PstColorSynthesis@MixedColorR,
        \PstColorSynthesis@MixedColorG,
        \PstColorSynthesis@MixedColorB}%
    \psset{fillstyle=solid,fillcolor=MixedColor}%
    \csname PstColorSynthesis@Surface#1\endcsname
    \endpsclip}

\def\PstColorSynthesis@MixedColor#1{%
    \edef\@tempa{#1}%
    \ifx\@tempa\@empty
    \else
    \pst@expandafter\PstColorSynthesis@MixedColor@i{%
        \csname\string\color@#1\endcsname}\@nil
    \fi}

\def\PstColorSynthesis@MixedColor@i#1 #2 #3 #4\@nil{%
    \PstColorSynthesis@MixedColor@ii{\PstColorSynthesis@MixedColorR}{#2}%
    \PstColorSynthesis@MixedColor@ii{\PstColorSynthesis@MixedColorG}{#3}%
      \PstColorSynthesis@MixedColor@ii{\PstColorSynthesis@MixedColorB}{#4}}   
\def\PstColorSynthesis@MixedColor@ii#1#2{%
    \pst@dimg=#1\p@
    \advance\pst@dimg by #2\p@
    \pst@dimtonum{\pst@dimg}{#1}}
\makeatother
\begin{document}

\begin{pspicture}(-2,-2)(4,4)
 \PstColorSynthesis[SurfaceA={\pscircle{2}}, 
    SurfaceB={\pscircle(2,0){2}},SurfaceC={\pscircle(1,2){2}},  
    ColorA=red,ColorB=green,ColorC=blue]
\end{pspicture}
\end{document}

enter image description here

相关内容