ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Metapost -- What am I doing wrong
@ 2005-12-25 18:08 David Arnold
  2005-12-25 23:02 ` Mojca Miklavec
  0 siblings, 1 reply; 3+ messages in thread
From: David Arnold @ 2005-12-25 18:08 UTC (permalink / raw)


All,

Can someone tell me what I am doing wrong here?

%Ouput=pdf

\setupcolors[state=start]

\definecolor[gridlines][s=0.7]

\startMPinclusions
   color gridlines; gridlines=\MPcolor{gridlines}
\stopMPinclusions


\startMPgraphic{create function path f 5-by-5}

   %define clipping path
   path cpath;
   cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;

   %create function path
   path p; p:=(-5,f(-5));
   for x=-5 step .1 until 5:
     p:=p--(x,f(x));
   endfor;
   p:=p--(5,f(5));

   %clip function path to clipping path
   p:=p cutbefore cpath;
   p:=reverse p;
   p:=p cutbefore cpath;

\stopMPgraphic

\startMPgraphic{scale and draw f 5-by-5}

   %scale function path
   p:=p scaled u;

   %draw function path
   drawdblarrow p withcolor blue;

\stopMPgraphic

\startMPgraphic{draw axis 5-by-5}

   %draw the grid
   for k=-5u step 1u until 5u:
     draw (k,-5u)--(k,5u) withcolor gridlines;
     draw (-5u,k)--(5u,k) withcolor gridlines;
   endfor;

   %draw axes
   drawdblarrow (-5.2u,0)--(5.2u,0);
   drawdblarrow (0,-5.2u)--(0,5.2u);

   %label axes
   label.rt(btex $x$ etex, (5.2u,0));
   label.top(btex $y$ etex, (0,5.2u));
   label.bot(btex $5$ etex, (5u,0));
   label.lft(btex $5$ etex, (0,5u));

\stopMPgraphic

\starttext

\startMPpage

   %define function
   vardef f(expr x)=
     x*x
   enddef;

   \useMPgraphic{create function path f 5-by-5}

   %initialize scale
   numeric u; 10u=2in;

   \useMPgraphic{draw axis 5-by-5}

   \useMPgraphic{scale and draw f 5-by-5}

   %draw plotted points
   for x=-2 step 1 until 2:
     drawdot ((x,f(x)) scaled u) withpen pencircle scaled 4pt withcolor
     blue;
   endfor;

\stopMPpage

\stoptext

%%% Local Variables:
%%% mode: conTeXt-en
%%% End:

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-25 23:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-25 18:08 Metapost -- What am I doing wrong David Arnold
2005-12-25 23:02 ` Mojca Miklavec
2005-12-25 23:48   ` David Arnold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).