<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>