Difference between revisions of "Command/startuseMPgraphic"

From Wiki
Jump to navigation Jump to search
(Add info about MPinstance)
Line 25: Line 25:
 
Define code for a MetaPost graphic. The graphic can be placed in the document with {{cmd|useMPgraphic}}, and will be recompiled every time it is placed.
 
Define code for a MetaPost graphic. The graphic can be placed in the document with {{cmd|useMPgraphic}}, and will be recompiled every time it is placed.
  
If a custom MetaPost instance should be used, the name of the MetaPost instance has to be provided as an argument followed by a double-colon and the MPgraphic name.
+
If a custom MetaPost instance should be used, the name of the graphic has to be preceded by the name of the MetaPost instance, with a double colon in between: {{cmd|startuseMPgraphic|{instancename::graphicname}|link=no}}.
  
 
== Example ==
 
== Example ==
<context source=yes>
+
<texcode>
 
\def\mycolor{.625red}
 
\def\mycolor{.625red}
  
Line 48: Line 48:
 
\def\mycolor{.625blue}
 
\def\mycolor{.625blue}
 
blue: \useMPgraphic{name}
 
blue: \useMPgraphic{name}
 +
</texcode>
 +
 +
 +
The command is very nice for defining [[Overlays|overlays]] that vary randomly:
 +
 +
<context source=yes>
 +
\startuseMPgraphic{randomcolor}
 +
fill unitsquare
 +
xyscaled (\overlaywidth, \overlayheight)
 +
                % `uniformdeviate 1` produces a random number between 0 and 1
 +
withcolor (uniformdeviate 1, uniformdeviate 1, uniformdeviate 1);
 +
\stopuseMPgraphic
 +
 +
\defineoverlay
 +
[beta]
 +
[\useMPgraphic{randomcolor}]
 +
 +
\dontleavehmode
 +
\framed[background=beta]{randomcolor}
 +
\framed[background=beta]{randomcolor}
 +
\framed[background=beta]{rather wide}
 
</context>
 
</context>
 +
  
 
== See also ==
 
== See also ==

Revision as of 17:04, 26 November 2012

\startuseMPgraphic

Syntax

\startuseMPgraphic{...}
%% MetaPost code
\stopuseMPgraphic
{...} name under which the graphic will be known


Description

Define code for a MetaPost graphic. The graphic can be placed in the document with \useMPgraphic, and will be recompiled every time it is placed.

If a custom MetaPost instance should be used, the name of the graphic has to be preceded by the name of the MetaPost instance, with a double colon in between: \startuseMPgraphic{instancename::graphicname}.

Example

\def\mycolor{.625red}

\defineMPinstance
  [myinstance]
  [metafun]

\startuseMPgraphic{myinstance::name}
  fill fullcircle scaled 20pt withcolor \mycolor;
\stopuseMPgraphic

\startuseMPgraphic{name}
  fill fullcircle scaled 20pt withcolor \mycolor;
\stopuseMPgraphic

red: \useMPgraphic{name}
red: \useMPgraphic{myinstance::name}

\def\mycolor{.625blue}
blue: \useMPgraphic{name}


The command is very nice for defining overlays that vary randomly:

\startuseMPgraphic{randomcolor}
	fill unitsquare
		xyscaled (\overlaywidth, \overlayheight)
                % `uniformdeviate 1` produces a random number between 0 and 1
		withcolor (uniformdeviate 1, uniformdeviate 1, uniformdeviate 1);
\stopuseMPgraphic

\defineoverlay
	[beta]
	[\useMPgraphic{randomcolor}]

\dontleavehmode
\framed[background=beta]{randomcolor}
\framed[background=beta]{randomcolor}
\framed[background=beta]{rather wide}


See also

Help from ConTeXt-Mailinglist/Forum

All issues with: