3

It is related to my previous question but with a little bit different requirement. Rather than editing the previous one that potentially makes "inconvenience" to the accepted answer, let me ask it separately.

Background

Bilateral closed curves can be constructed easily with \reversepath. For the sake of illustration, let's me take a simple example, i.e., drawing a helmet.

The following three macros define half part of head, eye and mouth curves of the helmet, respectively.

\documentclass[pstricks,border=1cm]{standalone}

\def\HalfHead{\psline(-2,2)(-3,4)(-4,1)(-4,-5)}
\def\HalfEye{\psline(-1,0)(-2,1)(-3,0)(-3,-2)}
\def\HalfMouth{\psline(-2,-3)(-2,-4)}

\begin{document}
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
\psset{linecolor=blue,arrows=->}
\HalfHead
\HalfEye
\HalfMouth
\end{pspicture}
\end{document}

enter image description here

The complete closed curves for head, eye and mouth can be obtained by enclosing each with a single \pscustom as follows.

\documentclass[pstricks,border=1cm]{standalone}

\def\HalfHead{\psline(-2,2)(-3,4)(-4,1)(-4,-5)}
\def\HalfEye{\psline(-1,0)(-2,1)(-3,0)(-3,-2)}
\def\HalfMouth{\psline(-2,-3)(-2,-4)}

\begin{document}
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
\pscustom
{
    \HalfHead
    \reversepath
    \scale{-1 1}
    \HalfHead
    \closepath
}
\pscustom
{
    \HalfEye
    \reversepath
    \scale{-1 1}
    \HalfEye
    \closepath
}
\pscustom
{
    \HalfMouth
    \reversepath
    \scale{-1 1}
    \HalfMouth
    \closepath
}
\end{pspicture}
\end{document}

enter image description here

Among other purposes (such as filling with gradient color, filling with a pattern, or clipping another image), I want to fill the region bounded by the head, eye and mouth with a solid red.

Unfortunately \pscustom cannot be nested. I have to use a single \pscustom as follows but the result is disappointing.

\documentclass[pstricks,border=1cm]{standalone}

\def\HalfHead{\psline(-2,2)(-3,4)(-4,1)(-4,-5)}
\def\HalfEye{\psline(-1,0)(-2,1)(-3,0)(-3,-2)}
\def\HalfMouth{\psline(-2,-3)(-2,-4)}

\begin{document}
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
\pscustom[fillstyle=eofill,fillcolor=red]
{
    \HalfHead
    \reversepath
    \scale{-1 1}
    \HalfHead
    \closepath

    \HalfEye
    \reversepath
    \scale{-1 1}
    \HalfEye
    \closepath

    \HalfMouth
    \reversepath
    \scale{-1 1}
    \HalfMouth
    \closepath
}
\end{pspicture}
\end{document}

enter image description here

Herbert's answer in my previous question uses a trick that seems to be cumbersome. It forces us to retrace the path.

Question

Recall that the built-in closed curves such as

  • psellipticwedge
  • psellipse
  • pscircle
  • pswedge
  • pspolygon
  • psframe
  • psccurve

can be used independently in a single \pscustom,

enter image description here

I think it will be better if I make each of the closed curves for head, eye and mouth a single independent object.

How to make

\HalfHead
\reversepath
\scale{-1 1}
\HalfHead
\closepath

as a single independent object for the head such that it can be used together later in a single pscustom? A solution in Metapost, Asympotote, Tikz, etc is also welcome!

2

I already gave you the answer in the other question!

\documentclass[pstricks,border=1cm]{standalone}

\def\HalfHead{\psline(0,-5)(-4,-5)(-4,1)(-3,4)(-2,2)(0,2)}
\def\HalfEye{\psline(0,-2)(-3,-2)(-3,0)(-2,1)(-1,0)(0,0)}
\def\HalfMouth{\psline(0,-4)(-2,-4)(-2,-3)(0,-3)}

\begin{document}
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
    \pscustom[fillstyle=eofill,fillcolor=red]{%
        \HalfHead
        \moveto(0,-2)
        \HalfEye
        \moveto(0,-4)
        \HalfMouth
        \reversepath
        \scale{-1 1}
        \HalfHead
        \moveto(0,-2)
        \HalfEye
        \moveto(0,-4)
        \HalfMouth
    }
\end{pspicture}
\end{document}

enter image description here

  • \moveto can be replaced by liftpen=2. – Money Oriented Programmer Dec 9 '17 at 3:10
  • Is internally the same! – user2478 Dec 9 '17 at 4:44
4

This is Asymptote code to make a single object gface from half parts of head, eye and mouth curves using evenodd PostScript fill rule in order to use it for filling and clipping:

// clcurve.asy
//
// run
// asy clcurve.asy
//
// to get clcurve.pdf
//    
settings.outformat="pdf";
import graph; size(9cm);
guide fpsline(... pair[] p){return graph(p);}

guide   HalfHead=fpsline((-2,2),(-3,4),(-4,1),(-4,-5));
guide   HalfEye=fpsline((-1,0),(-2,1),(-3,0),(-3,-2));
guide   HalfMouth=fpsline((-2,-3),(-2,-4));

guide[] g={HalfHead,HalfEye,HalfMouth};
guide[] gface;
for(var v:g) gface.push(v--reverse(scale(-1,1)*v)--cycle);
filldraw(gface,evenodd+orange,deepblue+0.8bp);

picture pic;

fill(pic,circle(0,100),lightyellow);
clip(pic,gface,evenodd);
add(shift(9,0)*pic);

enter image description here

  • It should be possible to apply this on PSTricks, I think. – Money Oriented Programmer Dec 7 '17 at 23:21
  • 1
    @Artificial Stupidity: It seems that there should be similar PostScript-level mechanism involved, so most probably, yes. – g.kov Dec 8 '17 at 0:09

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.