7

I just noticed that even-odd filling rule can only be used for solid and hatched filling. Sometimes, I need even-odd rule for gradient and as a clipper. How to do so? My code speaks the details.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-grad}

\newpsstyle{gradient}
{
    fillstyle=gradient,
    gradbegin=red,
    gradend=yellow,
    gradangle=30,
    gradmidpoint=0.5,
}

\newpsstyle{fill}
{
    fillstyle=eofill,
    fillcolor=orange,
}

\def\YinYang#1{%
\begin{pspicture}(-2,-2)(2,2)
    \pscustom[style=#1,dimen=monkey]
    {
        \pscircle(0,0){2}
        \moveto(.25,1)
        \pscircle(0,1){.25}
        \moveto(0,0)
        \psarc(0,-1){1}{90}{270}
        \psarc(0,0){2}{270}{90}
        \psarcn(0,1){1}{90}{270}
        \closepath
        \moveto(.25,-1)
        \pscircle(0,-1){.25}
    }
\end{pspicture}}

\begin{document}
\YinYang{fill}

% there are 2 failed cases:
% 1. with gradient style \YinYang{gradient}
% 2. using the \pscustom of \YingYang as a clipper

\end{document}

enter image description here

Note

Please don't suggest me to modify the paths and use zero filling rule.

Edit

Based on Herbert's answer below, the following case in which the path is used as a clipper still does not work.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=2]{example-grid-100x100pt}}

\psset
{
    xunit=.25\wd\IBox,
    yunit=.25\ht\IBox,
}
\begin{document}

\begin{pspicture}(-2,-2)(2,2)
\psclip{%
    \pscustom[dimen=monkey]
    {
        \code{/clip /eoclip load def}
        \pscircle(0,0){2}
        \moveto(.25,1)
        \pscircle(0,1){.25}
        \moveto(0,0)
        \psarc(0,-1){1}{90}{270}
        \psarc(0,0){2}{270}{90}
        \psarcn(0,1){1}{90}{270}
        \closepath
        \moveto(.25,-1)
        \pscircle(0,-1){.25}
    }}
\rput(0,0){\usebox\IBox}
\endpsclip
\end{pspicture}
\end{document}

enter image description here

  • I think the key-value formats defined for filling does not follow a logical pattern. – kiss my armpit Oct 21 '13 at 3:08
  • 1
    Not an answer (but I played around with it): \def\psfs@gradienteofill{\psfs@gradient\psfs@eofill} allows fillstyle=gradientoefill. This actually does the gradient first and then fills the correct path with white (or whatever the fillcolor is). – Qrrbrbirlbel Oct 21 '13 at 3:47
  • The culprit in your last MWE (with Edit heading) is the unit settings. – Not A Zoomed Image Sep 14 '17 at 3:18
5
\def\YinYang#1{%
\begin{pspicture}(-2,-2)(2,2)
    \pscustom[style=#1,dimen=middle]{   
        \code{ /clip /eoclip load def } %%%%%%%%%%%%%
        \pscircle(0,0){2}
        \moveto(.25,1)
        \pscircle(0,1){.25}
        \moveto(0,0)
        \psarc(0,-1){1}{90}{270}
        \psarc(0,0){2}{270}{90}
        \psarcn(0,1){1}{90}{270}
        \closepath
        \moveto(.25,-1)
        \pscircle(0,-1){.25}
    }
\end{pspicture}}

enter image description here

and the same with a picture:

\begin{pspicture}(-2,-2)(2,2)
\psclip{%
    \pscustom[dimen=middle]
    {
        \code{ /clip /eoclip load def }
        \pscircle(0,0){2}
        \moveto(.25,1)
        \pscircle(0,1){.25}
        \moveto(0,0)
        \psarc(0,-1){1}{90}{270}
        \psarc(0,0){2}{270}{90}
        \psarcn(0,1){1}{90}{270}
        \closepath
        \moveto(.25,-1)
        \pscircle(0,-1){.25}
    }}
\rput(0,0){\usebox\IBox}
\endpsclip
\end{pspicture}

enter image description here

| improve this answer | |
  • Is the \closepath necessary in this case? I noticed there is no difference when I removed the \closepath. – kiss my armpit Apr 22 '14 at 21:10
  • The first and third \moveto are no longer needed in the current pstricks. – Not A Zoomed Image Sep 14 '17 at 3:19
  • but doesn't hurt ... – user2478 Sep 14 '17 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.