<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\chapter{ĺ­Śä¸çš \METAPOST}

ćłĺżä˝&nbsp;ĺˇ˛čżŤä¸ĺĺžćłĺ­Śäš&nbsp; \METAPOST\ äşăčżĺ¤§ćŚćŻćĽčŞäşşçąťä¸ĺ¤ĺşĺ&nbsp;çĺ˛ĺ¨ăäşşçąťĺĺ­ŚäźçćŻçťçťďźčĺććŻćĺ­ăĺŞćŻä¸čŚĺŚĺžéčżčżĺşĺşä¸çŤ&nbsp;ĺĺŽšććĄ \METAPOSTďźĺ&nbsp;ä¸şĺłäşĺŽçĺ¨é¨ĺĺŽšďźčśłĺ¤ĺä¸ćŹčłĺ°ä¸çžĺ¤éĄľçäšŚçąäşăä¸čżďźćŹçŤ&nbsp;ĺĺŽščśłäťĽçťä˝&nbsp;ćĺźä¸ćçŞćˇďźčŽŠ \METAPOST\ çäźéć°ćŻćčżćśĺ¸¸čżäşä¸Ľčç \ConTeXt\ ä¸çă

\section{ä˝ĺžçŻĺ˘}

\METAPOST\ ćŻä¸ç§čŽĄçŽćşä˝ĺžčŻ­č¨ďźä¸ \TeX\ ä¸ć&nbsp;ˇďźçä¸şĺŽçźç¨čŻ­č¨ăä˝żç¨ \METAPOST\ čŻ­č¨çźĺçäťŁç&nbsp;ĺŻč˘Ť mpost ç¨ĺşçźčŻć PS ć&nbsp;źĺźçĺžĺ˝˘ćäťśăčŞ \LuaTeX\ ĺźĺ§ďźmpost çć&nbsp;¸ĺżĺč˝éćĺ°äş \LuaTeX\ ä¸­ďźäťć­¤äťĽĺďźĺ¨ \TeX\ çŻĺ˘ä¸­ä˝żç¨ \METAPOST\ čŻ­č¨ä˝ĺžäžżä¸éäžčľĺ¤é¨ç¨ĺşäşă

\ConTeXt\ ä¸ş \METAPOST\ äťŁç&nbsp;ćäžäşäşç§çŻĺ˘ďź

\starttyping
\startMPcode ... \stopMPcode
\startMPpage ... \stopMPpage
\startuseMPgraphic{name} ... \stopuseMPgraphic
\startuniqueMPgraphic{name} ... \stopuniqueMPgraphic
\startreusableMPgraphic{name} ... \stopreusableMPgraphic
\stoptyping

\noindent çŹŹä¸ç§çŻĺ˘ç¨äşä¸´ćśä˝ĺžďźçćçĺžĺ˝˘äźč˘ŤćĺĽĺ°äťŁç&nbsp;ćĺ¨ä˝ç˝ŽăçŹŹäşç§çŻĺ˘ćŻçćĺçŹçĺžĺ˝˘ćäťśďźäťĽä˝ĺśäťç¨éăĺé˘ä¸ç§çŻĺ˘ďźçćçĺžĺ˝˘ĺŻć&nbsp;šćŽçŻĺ˘çĺç§°ä˝ä¸şćçŤ&nbsp;ćĺžéĺ¤ä˝żç¨ďźä˝ĺŽäťŹĺćä¸ç§ä¸ĺç¨éďź

\startitemize[nowhite]
\item useMPgraphicďźćŻč˘Ťä˝żç¨ä¸ćŹĄďźĺŻšĺşç \METAPOST\ äťŁç&nbsp;äžżäźč˘Ťéć°çźčŻä¸ćŹĄă
\item uniqueMPgraphicďźĺŞčŚĺžĺ˝˘ćĺ¤çŻĺ˘ä¸ĺďź\METAPOST\ äťŁç&nbsp;ĺŞäźč˘ŤçźčŻä¸ćŹĄă
\item reusableMPgraphicďźć&nbsp;čŽşĺŚä˝ä˝żç¨ďźĺś \METAPOST\ ĺŞäźč˘ŤçźčŻä¸ćŹĄă
\stopitemize

\noindent ĺ¤§ĺ¤ć°ćĺľä¸ďźĺťşčŽŽéç¨ uniqueMPgraphicďźä˝čĽĺžĺ˝˘ä¸­ĺ­ĺ¨ä¸äşéčŚćŻćŹĄä˝żç¨ćśé˝čŚććĺĺçĺĺŽšďźĺŻéç¨ useMPgraphică

ĺŚĺ¤éčŚćł¨ćďźĺ¨ \ConTeXt\ ä¸­ä˝żç¨ \METAPOST\ ćśďźéĺ¸¸äźä˝żç¨ \ConTeXt\ ĺŽäšçä¸äş \METAPOST\ ĺŽďźčżäşĺŽććçéĺďźĺć° \MetaFună

\section{çťä¸ä¸Şçĺ­}

\METAPOST\ ä˝ĺžčŻ­ĺĽéľĺŽĺşćŹçčąćčŻ­ćłďźçč§ŁčľˇćĽé˘ä¸şçŽĺăäžĺŚďźç¨ç˛ĺşŚä¸ş 2 pt çĺĺ¤´çŹç¨ćçş˘č˛çťĺśä¸ćĄçťčż $(0, 0)$ďź$(3\,{\rm cm}, 0)$ďź$(3\,{\rm cm}, 1\,{\rm cm})$ďź$(0, 1\,{\rm cm})$ çĺ°é­čˇŻĺžďź

\startsample
\startMPcode
pickup pencircle scaled 2pt;
draw (0, 0) -- (3cm, 0) -- (3cm, 1cm)
     -- (0, 1cm) -- cycle withcolor darkred;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\noindent ä¸čż°äťŁç&nbsp;ä¸­ďź\type{(0, 0) -- ... -- cycle} ćé&nbsp;çćŻä¸ćĄĺ°é­čˇŻĺžďźĺŻĺ°ĺśäżĺ­äşčˇŻĺžĺéďź

\starttyping[option=MP]
path p;
p := (0, 0) -- (3cm, 0) -- (3cm, 1cm) -- (0, 1cm) -- cycle;
pickup pencircle scaled 2pt;
draw p withcolor darkred;
\stoptyping

\noindent ĺ°čˇŻĺžäżĺ­ĺ¨ĺéä¸­ďźćŻä¸şäşć´äžżäşĺŻščˇŻĺžčżčĄä¸äşčżçŽďźäžĺŚ

\startsample
\startMPcode
path p;
p := (0, 0) -- (3cm, 0)
     -- (3cm, 1cm) -- (0, 1cm) -- cycle;
pickup pencircle scaled 2pt;
draw p withcolor darkred;
draw p shifted (2cm, .5cm) withcolor darkblue;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\noindent čˇŻĺž \type{p} č˘Ťĺĺłĺšłç§ťäş 2 cmďźçť§čč˘Ťĺä¸ĺšłç§ťĺ¨äş 0.5 cmă

čżćä¸ç§ćé&nbsp;çŠĺ˝˘čˇŻĺžçćšćłďźĺćé&nbsp;ä¸ä¸Şĺä˝ć­Łćšĺ˝˘ďźçśĺĺŻšĺśçźŠćžăäžĺŚ

\startsample
\startMPcode
pickup pencircle scaled 2pt;
draw fullsquare xscaled 3cm yscaled 1cm
                withcolor darkred;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\MetaFun\ ĺŽ \type{randomized} ĺŻç¨äşĺŻščˇŻĺžéćşć°ĺ¨ăäžĺŚďźĺŻšä¸ä¸ŞĺŽ˝ä¸ş 3 cmďźéŤä¸ş 1cm ççŠĺ˝˘čˇŻĺžäťĽĺšĺşŚ 2mm çç¨ĺşŚäşäťĽć°ĺ¨ďź

\startsample
\startuseMPgraphic{éćşćĺ¨ççŠĺ˝˘}
pickup pencircle scaled 2pt;
draw (fullsquare xscaled 3cm yscaled 1cm)
                 randomized 2mm withcolor darkred;
\stopuseMPgraphic
\useMPgraphic{éćşćĺ¨ççŠĺ˝˘}
\stopsample
\simplesample[option=MP]{\getsample}

čżčŽ°ĺž overlay ĺďźĺŞčŚĺ°ä¸čż° useMPgraphic çŻĺ˘ćé&nbsp;çĺžĺ˝˘ĺśä˝ä¸ş overlayďźäžżĺŻĺ°ĺśä˝ä¸ş \type{\framed} çčćŻďźäťčĺŻäťĽĺžĺ°ä¸ç§ĺ¤č§é˘ä¸şĺŤč´ççĺ­ă

\startsample
\defineoverlay[ćć][\useMPgraphic{éćşćĺ¨ççŠĺ˝˘}]
\framed[frame=off,background=ćć,width=3cm]{ĺčžĺ˛ć}
\stopsample
\simplesample[option=TEX]{\getsample}

ĺ¨ \ConTeXt\ ä¸ş \METAPOST\ ćäžçä˝ĺžçŻĺ˘éďźĺŻĺĺŤéčż \type{\overlaywidth} ĺ \type{\overlayheight} čˇĺž overlay çĺŽ˝ĺşŚĺéŤĺşŚăĺ¨ĺ° overlay ä˝ä¸ş \type{\framed} çčćŻćśďź\type{\framed} çĺŽ˝ĺşŚĺéŤĺşŚäžżćŻ overlay çĺŽ˝ĺşŚĺéŤĺşŚăĺşäşčżä¸çšć§ďźäžżĺŻĺŽç° \METAPOST\ çťĺśçĺžĺ˝˘č˝ĺ¤čŞĺ¨éĺş \type{\framed} çĺŽ˝ĺşŚĺéŤĺşŚçĺĺăäžĺŚ

\startsample
\startuseMPgraphic{ć°çéćşćĺ¨ççŠĺ˝˘}
path p;
p := fullsquare xscaled \overlaywidth yscaled \overlayheight;
pickup pencircle scaled 2pt;
draw p randomized 2mm withcolor darkred;
\stopuseMPgraphic

\defineoverlay[ć°çćć][\useMPgraphic{ć°çéćşćĺ¨ççŠĺ˝˘}]
\framed
  [frame=off,background=ć°çćć]
  {äťĺ¤ŠĺŞććŽççčşŻĺŁłďźčżćĽĺčžĺ˛ćďźéŁé¨ä¸­ćąç´§čŞçąă}
\stopsample
\typesample[option=MP]  
\midaligned{\getsample}

ĺŻšäşéčŚéĺ¤ä˝żç¨ççĺ­ďźä¸şäşéżĺćŻćŹĄéĺ¤čŽžç˝Žĺść&nbsp;ˇĺźďźĺŻäťĽĺ°ĺŽĺŽäšä¸şä¸ç¨çĺ­ăäžĺŚ

\starttyping[option=TEX]
\defineframed[funnybox][frame=off,background=ć°çćć]
\funnybox{äťĺ¤ŠĺŞććŽççčşŻĺŁłďźčżćĽĺčžĺ˛ćďźéŁé¨ä¸­ćąç´§čŞçąă}
\stoptyping

\METAPOST\ ĺŻäťĽä¸şä¸ćĄĺ°é­čˇŻĺžĺĄŤĺé˘č˛ăĺ¨ć­¤éčŚćçĄŽďźä˝ä¸şĺ°é­čˇŻĺžăäžĺŚ

\starttyping[option=MP]
path p, q, r;
p := (0, 0) -- (1, 0) -- (1, 1) -- (0, 0) -- (0, 0);
q := (0, 0) -- (1, 0) -- (1, 1) -- (0, 0) -- cycle;
r := fullsquare;
\stoptyping

\noindent ĺśä¸­čˇŻĺž \type{p} ççťçšçĺć&nbsp;ć°ĺĽ˝ćŻĺśčľˇçšďźä˝ĺŽĺšśéĺ°é­čˇŻĺžďźččˇŻĺž \type{q} ĺ \type{r} çä¸şĺ°é­čˇŻĺžăä¸é˘ç¤şäžďźä¸şĺ°é­čˇŻĺžĺĄŤĺé˘č˛ďź

\startsample
\startMPcode
path p;
p := (fullsquare xscaled 3cm yscaled 1cm) randomized 2mm;
pickup pencircle scaled 2pt;
fill p withcolor darkgray;
draw p withcolor darkred;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\noindent ćł¨ćďźĺŻšäşĺ°é­čˇŻĺžďźĺşĺ˝ĺĺĄŤĺé˘č˛ďźĺçťĺśčˇŻĺžďźĺŚĺćĺĄŤĺçé˘č˛äźčŚçä¸é¨ĺčˇŻĺžçşżćĄă

\section{é˘č˛}

\METAPOST\ äťĽĺŤćä¸ä¸ŞĺéçĺéčĄ¨ç¤şé˘č˛ăĺéçä¸ä¸ŞĺéĺĺŤčĄ¨ç¤şçş˘č˛ăçťżč˛ĺčč˛ďźĺĺźčĺ´ä¸ş [0, 1]ďźäžĺŚ \type{(0.4, 0.5, 0.6)}ăĺŻĺ°é˘č˛äżĺ­ĺ° color çąťĺçĺéä¸­ďźäťĽĺ¤çťĺžä¸­éĺ¤ä˝żç¨ăäžĺŚĺŽäšä¸ä¸Şĺźä¸şćçş˘č˛çé˘č˛ĺéďź

\starttyping[option=MP]
color foo;
foo := (0.3, 0, 0);
\stoptyping

çąäş METAPOST ĺé¨ĺˇ˛çťĺŽäšäşç¨äşčĄ¨ç¤şçş˘č˛çĺé \type{red}ďźĺ&nbsp;ć­¤ \type{foo} çĺŽäšäšĺŻĺä¸ş

\starttyping[option=MP]
color foo;
foo := 0.3 * red;
\stoptyping

\noindent ĺ°äş 1 çĺć°ďźĺŻäťĽĺż˝çĽĺçź 0ďźä¸ĺŻäťĽç´ćĽä˝ç¨äşé˘č˛ďź

\starttyping[option=MP]
foo := .3red;
\stoptyping

ä˝żç¨ \type{transparent} ĺŽĺŻç¨äşćé&nbsp;ĺ¸ŚćéćĺşŚçé˘č˛ĺźăäžĺŚ

\startsample
\startMPcode
path p; p := fullsquare scaled 1cm;
color foo; foo := .3red;
pickup pencircle scaled 4pt;
draw p withcolor transparent (1, 0.3, foo);
draw p shifted (.5cm, .5cm) withcolor transparent (1, 0.25, blue);
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\noindent \type{transparent} ççŹŹä¸ä¸Şĺć°čĄ¨ç¤şéç¨çé˘č˛éććšćłďźĺąć 12 ç§ćšćłĺŻéďź

\startitemize[n,packed,columns,four]
\item normal
\item multiply
\item screen
\item overlay
\item softlight
\item hardlight
\item colordodge
\item colorburn
\item darken
\item lighten
\item difference
\item exclusion
\stopitemize
\noindent çŹŹäşä¸Şĺć°čĄ¨ç¤şéćĺşŚďźĺĺźčĺ´ [0, 1]ďźĺśĺźčśĺ¤§ďźéćç¨ĺşŚčśä˝ăçŹŹä¸ä¸Şĺć°ä¸şé˘č˛ĺźăéčŚćł¨ćçćŻďź\METAPOST\ ĺšśä¸ćŻćäťĽ \type{color} çąťĺçĺéäżĺ­ĺ¸ŚéćĺşŚçé˘č˛ĺźďźčä¸ \METAPOST\ éäšć˛Ąćä¸äšĺŻšĺşçĺéçąťĺă

\section{ćĺ­}

ä˝żç¨ \MetaFun\ ĺŽ \type{textext} ĺŻĺ¨ \METAPOST\ ĺžĺ˝˘ä¸­ćĺĽćĺ­ďźä¸ĺşäş \METAPOST\ ĺžĺ˝˘ĺć˘ĺ˝äť¤ĺŻĺŻšćĺ­čżčĄĺŽä˝ăçźŠćžăćč˝ŹăäžĺŚ

\startsample
\startMPcode
string s; % ĺ­çŹŚä¸˛çąťĺĺé
s = "\color[darkred]{\bf ćąĺąąĺŚć­¤ĺ¤ĺ¨}";
draw textext(s);
draw textext(s) shifted (4cm, 0);
draw textext(s) scaled 1.5 shifted (8cm, 0) ;
draw textext(s) scaled 1.5 rotated 45 shifted (12cm, 0);
\stopMPcode
\stopsample
\typesample[option=MP]
\midaligned{\getsample}

äšĺŻä˝żç¨ \type{\thetextext} ĺŽç´ćĽĺŻšćĺ­čżčĄĺŽä˝ďźäťčĺŻçĺť \type{shifted} ĺć˘ăäžĺŚ

\startsample
\startMPcode
string s; s = "{\bf ćąĺąąĺŚć­¤ĺ¤ĺ¨}";
draw (0, 0) withpen pensquare scaled 11pt withcolor darkred;
draw thetextext(s, (4cm, 0)) withcolor darkred;
\stopMPcode
\stopsample
\typesample[option=MP]
\getsample

\section{ćšĺčˇŻĺž}

\METAPOST\ ĺŽ \type{drawarrow} ĺŻçťĺśĺ¸ŚçŽ­ĺ¤´çčˇŻĺžăäžĺŚ

\startsample
\startMPcode
path p; p := (0, 0) -- (4cm, 0) -- (4cm, 2cm) -- (0, 2cm) -- (0, 1cm);
pickup pencircle scaled 2pt;
drawarrow p withcolor darkred;
drawarrow p shifted (6cm, 0) dashed (evenly scaled .5mm) withcolor darkred;
\stopMPcode
\stopsample
\typesample[option=MP]
\midaligned{\getsample}

\noindent ä¸čż°äťŁç&nbsp;äšçťĺşäşčçşżčˇŻĺžççťćłă

\METAPOST\ çäťťä˝ä¸ćĄčˇŻĺžďźäťčľˇçšĺ°çťçšĺŻĺşäşĺĺźčĺ´ä¸ş [0, 1] çĺć°éćŠčŻĽčˇŻĺžä¸çćä¸çšăĺşäşčŻĽĺč˝ĺŻĺŽç°čˇŻĺžć&nbsp;ćł¨ăäžĺŚéćŠčˇŻĺžĺć° 0.5 ĺŻšĺşççšďźĺ¨čŻĽçšĺłäž§ćžç˝Ž \ConTeXt\ ćč˝Ź 90 ĺşŚçćĺ­ďź

\startsample
\startMPcode
path p; p := (0, 0) -- (4cm, 0)
             -- (4cm, 2cm) -- (0, 2cm) -- (0, 1cm);
pair pos; pos := point .5 along p;
pickup pencircle scaled 2pt;
drawarrow p withcolor darkred;
draw pos withpen pensquare scaled 4pt
         withcolor darkgreen;
draw thetextext.rt("\rotate[rotation=-90]{čˇŻčż}",
                   pos shifted (1mm, 0));
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\noindent ä¸čż°äťŁç&nbsp;ä¸­ĺşç°äş \type{thetextext} çĺçźĺ˝˘ĺźăé¤äşéťčŽ¤ĺ˝˘ĺźďź\type{thetextext} čżć 4 ç§ĺçźĺ˝˘ĺźďźĺçźĺä¸ş \inframed{\type{.lft}}ďź\inframed{\type{.top}}ďź\inframed{\type{.rt}} ĺ \inframed{\type{.bot}}ďźĺĺŤčĄ¨ç¤şĺ°ćĺ­ćžĺ¨ćĺŽä˝ç˝ŽçĺˇŚäž§ăä¸ćšăĺłäž§ĺä¸ćšă

\section{çťé˘}

\METAPOST\ ćä¸ç§ĺéçąťĺ \type{picture}ďźĺŻĺ°ĺśç¨äşĺ°ä¸çťçťĺžčŻ­ĺĽĺĺšśä¸şä¸ä¸Şĺžĺ˝˘ďźçśĺäşäťĽçťĺśăä˝żç¨ \METAPOST\ ĺŽ \type{image} ĺŻćé&nbsp; \type{picture} ĺŽäžăäžĺŚ

\startsample
\startMPcode
path a; a := fullsquare xscaled 4cm yscaled 1cm;
picture p; p := image(
  fill a withcolor darkgray;
  draw a withpen pencircle scaled 2pt withcolor darkblue;
);
draw p;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

ä˝żç¨ \METAPOST\ ĺŽ \type{center} ĺŻäťĽčˇĺž \type{picture} ĺŽäžçä¸­ĺżĺć&nbsp;ďźçťćĺŻäżĺ­äşä¸ä¸Ş \type{pair} çąťĺçĺéăäžĺŚ

\startsample
\startMPcode
picture p; p := image(draw textext("ĺŻäşä¸é¨ďźčŞćčĽżé"););
pair c; c := center p;
draw c withpen pensquare scaled 4pt withcolor darkred;
draw p withcolor darkblue;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

ä˝żç¨ \MetaFun\ ĺŽ \type{bbwidth} ĺ \type{bbheight} ĺŻäťĽčˇĺž \type{picture} ĺŽäžçĺŽ˝ĺşŚĺéŤĺşŚăä˝żç¨čżä¸¤ä¸ŞĺŽďźĺŻä¸şäťťä˝ĺžĺ˝˘ĺćĺ­ćé&nbsp;čžšćĄăäžĺŚ

\startsample
\startMPcode
picture p; p := image(draw textext("ĺ˝ĺŚšććďźčżĺ˝ććś"));
numeric w, h; w := bbwidth(p); h := bbheight(p);
path q; q := fullsquare xscaled w yscaled h;
fill q withcolor darkgray;
draw q withpen pencircle scaled 2pt withcolor darkred;
draw p;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\noindent ä¸čż°ĺŽäžä¸şćĺ­ćé&nbsp;çčžšćĄĺ¤Şç´§äşďźĺŠç¨ç°ććĺ­ŚďźčŽŠĺŽĺŽ˝ćžä¸äşĺšśä¸ĺ°éžďź

\startsample
\startMPcode
picture p; p := image(draw textext("ĺ˝ĺŚšććďźčżĺ˝ććś"));
numeric w, h; w := bbwidth(p); h := bbheight(p);
numeric offset; offset := 5mm;
path q;
q := fullsquare xscaled (w + offset)
                yscaled (h + offset)
                shifted center p;
fill q withcolor darkgray;
draw q withpen pencircle scaled 2pt withcolor darkred;
draw p;
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\section[macro]{ĺŽ}

ĺŽäšä¸ä¸ŞĺŽďźäť¤ĺśćĽĺä¸ä¸Şĺ­çŹŚä¸˛çąťĺçĺć°ďźčżĺä¸ä¸ŞçŠĺ˝˘ćĄďźĺšśäť¤ćĺ­ĺąäşçŠĺ˝˘ćĄä¸­ĺżďź

\startsample
\startMPcode
vardef framed (expr text, offset) =
  picture p; p := image(draw textext(text));
  numeric w, h; w := bbwidth(p); h := bbheight(p);
  path q;
  q := fullsquare xscaled (w + offset) yscaled (h + offset) shifted center p;
  image(fill q withcolor lightgray;
        draw q withpen pencircle scaled 2pt withcolor darkred;
        draw p;)
enddef;
draw framed("{\bf äş˘éžćć}", 5mm);
\stopMPcode
\stopsample
\simplesample[option=MP]{\getsample}

\METAPOST\ ç \type{vardef} ç¨äşĺŽäšä¸ä¸ŞćčżĺĺźçĺŽďźĺŽĺŽäšçćĺä¸ćĄčŻ­ĺĽĺłčżĺĺźďźčŻĽćĄčŻ­ĺĽä¸ĺŻäťĽĺĺˇä˝ä¸şçťĺ°žă\METAPOST\ čżćĺśäťĺ&nbsp;ç§ĺŽĺŽäšĺ˝˘ĺźďźä˝ćŻĺŻšäşĺ¤§ĺ¤ć°ä˝ĺžäťťĺĄčč¨ďź\type{vardef} ĺˇ˛čśłĺ¤ĺşäťă

\section[sec:flow-chart]{çťä¸ĺšçŽĺçćľç¨ĺž}

ç°ĺ¨ďźčŻˇčˇéćć˛ĺťéŽççććďźéć­Ľçťä¸ĺšćčż°ć°ĺ­ćąĺčżç¨çćľç¨ĺžďźĺ¸ćčżćŹĄćç¨č˝čŽŠä˝&nbsp;ĺŻš \METAPOST\ çĺşćŹčŻ­ćłćä¸äşĺ¨é˘çčŽ¤čŻă

éŚĺďźćé&nbsp;ä¸ä¸ŞçťçšďźčĄ¨ç¤şć°ćŽčžĺĽââ

\starttyping[option=MP]
string f; f := "\framed[frame=off,align=center]";
picture a;
a := image(
  % çŹŚĺˇ &amp; ç¨äşćźćĽä¸¤ä¸Şĺ­çŹŚä¸˛
  draw textext(f &amp; "{$i\leftarrow 1$\\$s\leftarrow 0$}");
);
\stoptyping

çśĺďźç¨ \in[macro] čĺŽäšç \type{framed} ĺŽćé&nbsp;ä¸¤ä¸ŞčżçŽčżç¨çťçšďź

\starttyping[option=MP]
numeric offset; offset := 5mm;
picture b; b := framed(f &amp; "{$s\leftarrow s + i$}", offset);
picture c; c := framed(f &amp; "{$i\leftarrow i + 1$}", offset);
\stoptyping

čżéčŚĺŽäšä¸ä¸ŞĺŽďźç¨ĺŽćé&nbsp;čąĺ˝˘çćĄäťśĺ¤ć­çťçšďź

\starttyping[option=MP]
vardef diamond (expr text, offset) =
  picture p; p := image(draw textext(text));
  numeric w, h; w := bbwidth(p); h := bbheight(p);
  path q;
  q := fulldiamond xscaled (w + offset) yscaled (h + offset) shifted center p;
  image(fill q withcolor darkgray;
        draw q withpen pencircle scaled 2pt withcolor darkred;
        draw p withcolor white;)
enddef;
picture d; d := diamond(f &amp; "{$i &gt; 100$}", 3 * offset);
\stoptyping

ćĺďźĺćé&nbsp;ä¸ä¸ŞçťçščĄ¨ç¤şç¨ĺşčžĺşďź

\starttyping[option=MP]
picture e;
e := image(draw textext(f &amp; "{$s$}"););
\stoptyping

äżćçťçš \type{a} ä¸ĺ¨ďźĺŻš \type{b}ďź\type{c}ďź\type{d} ĺ \type{e} čżčĄĺŽä˝ďź

\starttyping[option=MP]
b := b shifted (0, -2cm);
c := c shifted (4cm, -4.5cm);
d := d shifted (0, -4.5cm);
e := e shifted (0, -7cm);
\stoptyping

ç°ĺ¨ĺŻäťĽçťĺşććçťçšäşďźĺł

\starttyping[option=MP]
draw a; draw b; draw c; draw d; draw e;
\stoptyping
\midaligned{\externalfigure[12/flowchart-1.pdf][frame=on]}
\blank

ç°ĺ¨ĺźĺ§ćé&nbsp;čżćĽĺçťçšçčˇŻĺžăéŚĺćé&nbsp;çťçš \type{a} çĺşé¨ä¸­çšĺ° \type{b} çéĄśé¨ä¸­çšçčˇŻĺžďź

\starttyping[option=MP]
path ab;
ab := .5[llcorner a, lrcorner a] -- .5[ulcorner b, urcorner b];
\stoptyping

\noindent ĺśä¸­ \type{llcorner} ç¨äşčˇĺčˇŻĺžćçťé˘ĺŽäžçćĺ°ĺĺ´ççĺˇŚä¸č§éĄśçšĺć&nbsp;ăĺçďź\type{ulcorner}ďź\type{urcorner} ĺ \type{lrcorner} ĺĺŤčˇĺĺĺ´ççĺˇŚä¸č§ăĺłä¸č§ĺĺłä¸č§éĄśçšĺć&nbsp;ă\type{.5[..., ...]} ç¨äşčŽĄçŽä¸¤ä¸Şçščżçşżçä¸­çšă

ç¨çąťäźźçćšćłĺŻäťĽćé&nbsp;ĺśäťčżćĽĺçťçšçčˇŻĺžďź

\starttyping[option=MP]
path bd;
bd := .5[llcorner b, lrcorner b] -- .5[ulcorner d, urcorner d];
path dc;
dc := .5[lrcorner d, urcorner d] -- .5[ulcorner c, llcorner c];
path cb;
cb := .5[ulcorner c, urcorner c] -- (4cm, -2cm) -- .5[urcorner b, lrcorner b];
path de;
de := .5[llcorner d, lrcorner d] -- .5[ulcorner e, urcorner e];
\stoptyping

çťĺşććčˇŻĺžďź

\starttyping[option=MP]
drawarrow ab withcolor darkred; drawarrow bd withcolor darkred;
drawarrow cb withcolor darkred; drawarrow dc withcolor darkred;
drawarrow de withcolor darkred;
\stoptyping
\midaligned{\externalfigure[12/flowchart-2.pdf][frame=on]}
\blank

ćĺä¸ć­ĽďźčˇŻĺžć&nbsp;ćł¨ďź

\starttyping[option=MP]
pair no;  no  := point .4 along dc;
pair yes; yes := point .5 along de;
draw thetextext.top("ĺŚ", no);
draw thetextext.rt("ćŻ", yes);
\stoptyping
\midaligned{\externalfigure[12/flowchart-3.pdf][frame=on]}

\section{äťŁç&nbsp;çŽĺ}

\in[sec:flow-chart] čä¸­ç¨äşçťĺśç¨ĺşćľç¨ĺžçäťŁç&nbsp;ĺ­ĺ¨čŽ¸ĺ¤éĺ¤ăćäťŹĺŻäťĽĺ°čŻä˝żç¨ćĄäťśăĺžŞçŻďźĺŽç­ĺ˝˘ĺźĺŻšäťŁç&nbsp;čżčĄçŽĺďźä˝ćĺŻšĺŽäťŹçťĺşçčŽ˛č§Łĺšśä¸äźçťč´ďźä¸şçć­ŁćŻčľ°éŠŹč§čąďźč§ĺśĺ¤§çĽă

éŚĺďźč§ĺŻĺŽ \type{framed} ĺ \type{diamond} çĺŽäšďźĺç°äşčäťćçä¸ĺćŻĺčç¨ \type{fullsquare} çťĺśçĺ­ďźĺčç¨ \type{fulldiamond}ăĺ&nbsp;ć­¤ďźĺŻäťĽéć°ĺŽäšä¸ä¸Şć´ä¸şçľć´ťçĺŽďźç¨äşĺśä˝çťçšďź

\starttyping[option=MP]
vardef make_node(expr text, shape, offset) =
  picture p; p := image(draw textext(text));
  numeric w, h; w := bbwidth(p); h := bbheight(p);
  if path shape:
    path q;
    q := shape xysized (w + offset, h + offset) shifted center p;
    image(fill q withcolor lightgray;
          draw q withpen pencircle scaled 2pt withcolor darkred;
          draw p;)
  else:
    image(draw p;)
  fi
enddef;
\stoptyping

\noindent çąäşä¸čż°äťŁç&nbsp;ä˝żç¨äş \METAPOST\ çćĄäťśĺ¤ć­čŻ­ćłďźäťĽ \type{path shape} ĺ¤ć­ \type{shape} ćŻĺŚä¸şčˇŻĺžĺéďźäťčä˝żĺž \type{make_node} č˝ćç¨äşćé&nbsp;ćć&nbsp;čžšćĄĺćčžšćĄççťçšďź

\starttyping[option=MP]
numeric offset; offset := 5mm;
string f; f := "\framed[frame=off,align=center]";
picture a, b, c, d, e;
a := make_node(f &amp; "{$i\leftarrow 1$\\$s\leftarrow 0$}", none, 0);
b := make_node(f &amp; "{$s\leftarrow s + i$}", fullsquare, offset);
c := make_node(f &amp; "{$i\leftarrow i + 1$}", fullsquare, offset);
d := make_node(f &amp; "{$i &gt; 100$}", fulldiamond, offset);
e := make_node(f &amp; "{$s$}", none, 0);
\stoptyping

ĺ¨ \type{vardef} ĺŽä¸­ä˝żç¨ćĄäťśčŻ­ĺĽćśéčŚćł¨ćďźéĺ¸¸ćĺľä¸ä¸čŚćĄäťśçťćčŻ­ĺĽ \type{fi} ĺé˘ćˇťĺ&nbsp;ĺĺˇďźĺŚĺ \type{vardef} ĺŽçčżĺĺźäźĺ¸Śä¸čżä¸Şĺĺˇăĺ¨ĺśäťćĺ˘ä¸ďźéĺ¸¸éčŚĺ¨  \type{fi} ĺ&nbsp;ĺĺˇăčżčŚćł¨ćďźćĺ¨ \type{make_node} ĺŽä¸­ä˝żç¨ \type{xysized} ĺäťŁäşäšĺç \type{xscale} ĺ \type{yscale}ďźĺŻç´ćĽćĺŽčˇŻĺžćçťé˘çĺ°şĺŻ¸ăäšćäťĽĺŚć­¤ďźćŻĺ&nbsp;ä¸şćäťŹć&nbsp;ćłçĄŽĺŽ \type{make_node} ĺŽççŹŹ 2 ä¸Şĺć°ĺŻšĺşçčˇŻĺžćŻĺŚä¸şć&nbsp;ĺĺžĺ˝˘ă

ĺ¨çťĺśçťçšĺčˇŻĺžćśďźĺ­ĺ¨éĺ¤ä˝żç¨ \type{draw} čŻ­ĺĽçćĺľďźäžĺŚ

\starttyping[option=MP]
drawarrow ab withcolor darkred;
drawarrow bd withcolor darkred;
drawarrow cb withcolor darkred;
drawarrow dc withcolor darkred;
drawarrow de withcolor darkred;
\stoptyping

\noindent ĺŻä˝żç¨ĺžŞçŻčŻ­ĺĽäşäťĽçŽĺďź

\starttyping[option=MP]
for i = ab, bd, cb, dc, de:
  draw i withcolor darkred;
endfor; 
\stoptyping

ä¸şäşäžżäşčˇĺžčˇŻĺžćçťé˘çĺĺ´ççĺčžšä¸­çšďźĺŽäšäťĽä¸ĺŽďź

\starttyping[option=MP]
vardef left(expr p) = .5[llcorner p, ulcorner p] enddef;
vardef top(expr p) = .5[ulcorner p, urcorner p] enddef;
vardef right(expr p) = .5[lrcorner p, urcorner p] enddef;
vardef bottom(expr p) = .5[llcorner p, lrcorner p] enddef;
\stoptyping

\noindent äťĽçťĺśçťçš \type{b} çĺčžšä¸­çšä¸şćľčŻç¨äž

\starttyping[option=MP]
for i = left(b), top(b), right(b), bottom(b):
  draw i withpen pensquare scaled 4pt withcolor darkblue;
endfor;
\stoptyping
\midaligned{\externalfigure[12/flowchart-4.pdf]}

ĺşäşä¸čż°ĺŽďźĺŻäťĽć´ä¸şçŽć´ĺ°ćé&nbsp;čżćĽĺçťçšçčˇŻĺžďź

\starttyping[option=MP]
path ab; ab := bottom(a) -- top(b);
path bd; bd := bottom(b) -- top(d);
path dc; dc := right(d) -- left(c);
path cb; cb := top(c) -- (xpart center c, ypart center b) -- right(b);
path de; de := bottom(d) -- top(e);
\stoptyping

\noindent \type{center} ćŻ \METAPOST\ ĺŽďźĺŻç¨äşčˇĺčˇŻĺžćçťé˘çĺĺ´çä¸­ĺżçšĺć&nbsp;ă\type{xpart} ĺ \type{ypart} äšçä¸ş \METAPOST\ ĺŽďźç¨äşčˇĺçšçĺć&nbsp;ĺéă

čˇŻĺžć&nbsp;ćł¨äšĺŻäťĽéčżĺŽäšä¸ä¸ŞĺŽäşäťĽçŽĺďź

\starttyping[option=MP]
vardef tag(expr p, text, pos, loc) =
  if loc = "left": thetextext.lft(text, point pos along p)
  elseif loc = "right": thetextext.rt(text, point pos along p)
  elseif loc = "top": thetextext.top(text, point pos along p)
  elseif loc = "bottom": thetextext.bot(text, point pos along p)
  else thetextext(text, point pos along p)
  fi
enddef;
\stoptyping

\noindent ĺśç¨ćłä¸ş

\starttyping[option=MP]
draw tag(dc, "ĺŚ", .5, "top"); draw tag(de, "ćŻ", .5, "right");
\stoptyping


\section{ĺąĺąĺ&nbsp;ĺ&nbsp;}

\ConTeXt\ ćä¸ä¸ŞäťĽ overlay ä¸şĺşçĄçĺąďźLayerďźćşĺśăĺŠç¨ĺąćşĺśďźćäťŹĺŻĺ° \METAPOST\ ĺžĺ˝˘çťĺśĺ¨éĄľé˘ä¸çäťťä˝ä¸ä¸Şä˝ç˝Žăĺ¨ĺ­Śäš&nbsp;ĺąäšĺďźćäťŹéčŚĺŻš overlay çčŽ¤čŻĺĺ&nbsp;ćˇąä¸äşă

\subsection{overlay}

ĺŽéä¸ overlay çŻĺ˘ćŻä¸ä¸Şĺžĺ˝˘ăć&nbsp;ăăéčżĺŽďźĺŻĺŽç°ĺžĺ˝˘ďźĺćŹćĺ­ďźçĺ&nbsp;ĺ&nbsp;ăäžĺŚďźĺŻšäşäťĽä¸ \METAPOST\ ĺžĺ˝˘ďź

\startsample
\startuseMPgraphic{ä¸ä¸ŞçŠĺ˝˘}
path p; p := fullsquare xscaled 4cm yscaled 1cm;
draw p randomized 3mm
       withcolor transparent (1, .5 randomized .25, red)
       withpen pencircle scaled 2pt;
\stopuseMPgraphic
\startoverlay
  {\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
  {\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
  {\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\stopoverlay
\stopsample
\simplesample[option=MP]{\getsample}

\noindent ä¸čż°äťŁç&nbsp;ä¸­ďź\type{transparent (1, .5 randomized .3, red)} ç¨äşćé&nbsp;ĺ¨ä¸ĺŽç¨ĺşŚä¸ä¸çĄŽĺŽéćĺşŚççş˘č˛ďźéćĺşŚĺ¨ [0.2, 0.8] äšé´ďźäşŚĺł \type{randomized} ä¸äťĺŻä˝ç¨äşčˇŻĺžďźäšĺŻä˝ç¨äşć°ĺ­ćé˘č˛ĺźăçąäşä¸čż° \METAPOST\ ĺžĺ˝˘çŻĺ˘ĺĺŤçéćşĺĺŽšďźĺ°ĺśä˝ä¸şćĺžďźĺ¨ä¸ä¸Ş overlay ä¸­ĺ¤ćŹĄä˝żç¨ďźćŻćŹĄä˝żç¨é˝äźäş§çä¸ĺççťćďźĺ¨ overlay ä¸­ĺŽäťŹäźč˘Ťĺ&nbsp;ĺ&nbsp;ĺ°ä¸čľˇă

äšĺĺ¨ä¸ş \type{\framed} ĺŽäš overlay ćśďźoverlay ä¸­ĺŞćĺä¸Şĺžĺ˝˘ďźäşŚĺłćäťŹĺšśćŞĺĺĺŠç¨ overlay ççšć§ăäťĽä¸äťŁç&nbsp;ĺŽäšç \type{\framed} çčćŻäžżĺĺŤäşä¸ä¸Şĺ&nbsp;ĺ&nbsp;ç overlayďź

\startsample
\defineoverlay
  [ĺ&nbsp;ĺ&nbsp;]
  [\startoverlay
     {\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
     {\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
     {\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
   \stopoverlay]
\defineframed
  [foo]
  [frame=off,background={ĺ&nbsp;ĺ&nbsp;},width=4cm]
\foo{čżćĽĺčžĺ˛ć}
\stopsample
\simplesample[option=TEX]{\getsample}

\noindent \type{\framed} çčćŻćŻćĺ¤ä¸Ş overlay ĺ&nbsp;ĺ&nbsp;ďźäťĽä¸äťŁç&nbsp;ä¸ä¸äžç­ćďź

\starttyping[option=TEX]
\defineoverlay[ĺ&nbsp;ĺ&nbsp;-1]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\defineoverlay[ĺ&nbsp;ĺ&nbsp;-2]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\defineoverlay[ĺ&nbsp;ĺ&nbsp;-3]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\defineframed[foo][frame=off,background={ĺ&nbsp;ĺ&nbsp;-1,éĺ&nbsp;-2,éĺ&nbsp;-3}]
\foo{čżćĽĺčžĺ˛ć}
\stoptyping

\noindent čżćĺłçďź\type{\framed} çčćŻďźćŹč´¨ä¸äšćŻä¸ä¸Ş overlayă

ĺşäş overlayďźäšĺŻä¸şććĄŁčŽžç˝Žć°´ĺ°ăäžĺŚďźčĽĺ¨ \type{\starttext} äšĺćˇťĺ&nbsp;äťĽä¸äťŁç&nbsp;ďź

\starttyping[option=TEX]
\startuseMPgraphic{square}
path p; p := fullsquare xscaled 4cm yscaled 1cm;
draw p randomized 3mm
       withcolor transparent (1, .5 randomized .3, red)
       withpen pencircle scaled 2pt;
\stopuseMPgraphic
\defineoverlay[watermark][\useMPgraphic{square}]
\setupbackgrounds[page][background=watermark]
\stoptyping
\midaligned{\externalfigure[12/watermark.png][width=.6\textwidth]}

\subsection[layer]{ĺą}

\ConTeXt\ çĺąďźćŹč´¨ä¸ćŻä¸ä¸ŞĺŻä˝ä¸şĺ¨éĄľčćŻç overlayďźĺŻä˝żç¨çťĺŻšĺć&nbsp;ćç¸ĺŻšĺć&nbsp;ĺŻšćçĺç´&nbsp;ĺ¨éĄľé˘ä¸ĺŽä˝ćžç˝ŽăäžĺŚďźĺŽäšä¸ä¸Şĺą fooďźĺ¨ä¸ä¸Şä¸ĺä˝ç˝ŽĺĺŤćžç˝Žä¸ĺš \METAPOST\ ĺžĺ˝˘ďźĺšśĺ°ĺśä˝ç¨äşĺ˝ĺéĄľé˘ďź

\starttyping[option=TEX]
\definelayer[foo]
\setlayer[foo][x=0cm,y=0cm]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\setlayer[foo][x=6cm,y=1cm]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\stoptyping
\starttyping[option=TEX]
\setlayer
  [foo]
  [x=\textwidth,y=2cm,hoffset=-4cm,vhoffset=-.5cm]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\flushlayer[foo]
\stoptyping
\definelayer[test]
\setlayer[test][x=0cm,y=0cm]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\setlayer[test][x=6cm,y=1cm]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\setlayer
  [test]
  [x=\textwidth,y=2cm,hoffset=-4cm,voffset=-3cm]{\useMPgraphic{ä¸ä¸ŞçŠĺ˝˘}}
\flushlayer[test]
\noindent ä¸čż°äťŁç&nbsp;ĺŽäšçĺą fooďźĺśĺć&nbsp;ĺçšćŻĺąč˘Ťććžçä˝ç˝ŽďźäşŚĺłĺ¨ćŹčĄćĺ­çĺˇŚä¸č§ă$x$ ĺć&nbsp;ĺĺłéĺ˘ďź$y$ ĺć&nbsp;ĺä¸éĺ˘ă
\definelayer[foo]
\setlayer[foo][x=0cm,y=0cm]{\useMPgraphic{circle}}
\setlayer[foo][preset=rightbottom]{\useMPgraphic{circle}}
\setupbackgrounds[page][background=foo]

ĺŚćĺ°ĺąçĺŽ˝ĺşŚĺéŤĺşŚĺĺŤčŽžä¸şéĄľé˘çĺŽ˝ĺşŚĺéŤĺşŚďźĺšśĺ°ĺśčŽžä¸şéĄľé˘čćŻďźĺĺć&nbsp;ĺçšĺ¨éĄľé˘çĺˇŚä¸č§ďźä¸ĺŻä˝żç¨ä¸äşé˘ĺŽäšä˝ç˝ŽććžĺĺŽšăäžĺŚäťĽä¸äťŁç&nbsp;ĺŻĺ¨ĺ˝ĺéĄľé˘çĺˇŚä¸č§ĺĺłä¸č§ä˝ç˝Žĺćžä¸ä¸Şĺĺďź

\starttyping[option=TEX]
\startuniqueMPgraphic{circle}
draw fullcircle scaled 2cm withpen pencircle scaled 2pt withcolor darkgreen;
\stopuniqueMPgraphic
\definelayer[foo][width=\paperwidth,height=\paperheight]
\setlayer[foo][x=0cm,y=0cm]{\uniqueMPgraphic{circle}}
\setlayer[foo][preset=rightbottom]{\uniqueMPgraphic{circle}}
\setupbackgrounds[page][background=foo]
\stoptyping
\startuniqueMPgraphic{circle}
draw fullcircle scaled 2cm withpen pencircle scaled 2pt withcolor darkgreen;
\stopuniqueMPgraphic
\definelayer[foo][width=\paperwidth,height=\paperheight]
\setlayer[foo][x=0cm,y=0cm]{\uniqueMPgraphic{circle}}
\setlayer[foo][preset=rightbottom]{\uniqueMPgraphic{circle}}
\setupbackgrounds[page][background=foo]

\noindent éčŚćł¨ćçćŻďźĺąč˘Ťä˝żç¨ä¸ćŹĄĺďźäžżäźč˘Ťć¸çŠşďźĺ&nbsp;čĺ°ĺśä˝ä¸şéĄľé˘čćŻďźäťĺŻšĺ˝ĺéĄľććă

éčż \type{preset} ĺć°ĺŻč°ć´ĺąçĺć&nbsp;ĺçšĺĺć&nbsp;ćšĺăĺ¨ä¸čż°äťŁç&nbsp;ä¸­ďź\type{rightbottom} ĺŻĺ°ĺąçĺć&nbsp;ĺçšĺŽä˝äşĺąçĺłä¸č§ďźĺćś $x$ ĺć&nbsp;ćšĺĺä¸şĺĺˇŚéĺ˘ďź$y$ ĺć&nbsp;ćšĺĺä¸şĺä¸éĺ˘ă

\ConTeXt\ é˘ĺŽäšç \type{preset} ĺć°ĺźć

\startitemize[packed,columns,five]
\item lefttop\item righttop\item leftbottom\item rightbottom\item middle\item middletop
\item middlebottom\item middleleft\item middleright\item lefttopleft\item lefttopright
\stopitemize

\noindent ä˝żç¨čżäşĺć°ĺźćśďźčŚćł¨ćĺć&nbsp;ćšĺăäžĺŚďźčĽ \type{preset=middleright}ďźĺś $x$ ĺć&nbsp;ćšĺĺä¸şĺĺˇŚéĺ˘ďźč $y$ ĺć&nbsp;ćšĺäžçśäżćĺä¸éĺ˘ďźäťĽä¸äťŁç&nbsp;ĺŻäşäťĽéŞčŻďź

\starttyping[option=TEX]
\definelayer[bar][width=\paperwidth,height=\paperheight]
\setlayer[bar][preset=middleright]{
  \startMPcode
  draw (0, 0) withpen pensquare scaled 12pt withcolor darkred;
  \stopMPcode
}
\stoptyping
\starttyping[option=TEX]
\setlayer[bar][preset=middleright,x=2cm,y=2cm]{
  \startMPcode
  draw (0, 0) withpen pensquare scaled 12pt
              withcolor transparent (1, .3, darkred);
  \stopMPcode
}
\setupbackgrounds[page][background=bar]
\stoptyping

\definelayer[bar][width=\paperwidth,height=\paperheight]
\setlayer[bar][preset=middleright]{
  \startMPcode
  draw (0, 0) withpen pensquare scaled 12pt withcolor darkred;
  \stopMPcode
}
\setlayer[bar][preset=middleright,x=2cm,y=2cm]{
  \startMPcode
  draw (0, 0) withpen pensquare scaled 12pt
              withcolor transparent (1, .3, darkred);
  \stopMPcode
}
\setupbackgrounds[page][background=bar]

\section{ĺ°çť}

äščŽ¸ä˝&nbsp;ćçšćŞĺ°˝ďźçčłč§ĺžćčŻ­çä¸čŻŚăĺčŤćŞćďźćĺćŹäťäťćŻäťçťĺŚä˝ä˝żç¨ \METAPOST\ çťĺśä¸ä¸ŞčžšćĄĺéćşć°ĺ¨ççĺ­ăä¸čżďźĺ¨ĺ¤§č´ććĄäşćŹçŤ&nbsp;ćčż°çĺĺŽšçĺşçĄä¸ďźĺłäş \METAPOST\ ć´ĺ¤ççĽčŻďźçšĺŤćŹçŤ&nbsp;ććä˝&nbsp;č§ĺžčŻ­çä¸čŻŚäšĺ¤ďźçĺŻéčŻťĺŽçćĺ\cite[mpman]äťĽĺ˘čżčŽ¤čŻăć­¤ĺ¤ďź\ConTeXt\ ĺźĺč Hans Hagen ćĺç \MetaFun\ ćĺé¤äşčŽ˛čż° \MetaFun\ äšĺ¤äšĺ¤§éäťçťäş \METAPOST\ çĺşćŹçĽčŻĺćĺˇ§ďźčŻĽćĺĺ¨ä˝&nbsp;ç \ConTeXt\ çłťçťä¸­ďźä˝żç¨äťĽä¸ĺ˝äť¤ćĽćžďź

\starttyping
$ mtxrun --script base --search metafun-s.pdf
\stoptyping</pre></body></html>