[NTG-context] Metapost and Metafun

Hans Hagen pragma at wxs.nl
Wed May 21 20:21:27 CEST 2014


On 5/21/2014 7:55 PM, Fabrice Couvreur wrote:
> Hi,
> As PSTricks (which I prefer) is not yet well integrated, I decided to
> learn Metapost starting with a simple code.
>
> \starttext
> \startMPcode
> numeric xmin, xmax, ymin, ymax;
> xmin := -2.5; xmax := 2.5; ymax :=2.5 ;ymin:=-2.5; u := 2cm;
> vardef f(expr x) = -x*x+1 enddef;
> xinc := 0.001;
> path pts_f;
> pts_f := (xmin,f(xmin))*u
> for x=xmin+xinc step xinc until xmax+xinc:
> .. (x,f(x))*u
> endfor;
> path axe_x,axe_y;
> path screen;
> screen=(xmin,ymin)*u--(xmax,ymin)*u--(xmax,ymax)*u--(xmin,ymax)*u--cycle;
> axe_x = (xmin,0)*u -- (xmax,0)*u;
> axe_y = (0,ymin)*u -- (0,ymax)*u;
> drawarrow axe_x;
> drawarrow axe_y;
> draw pts_f withpen pencircle scaled 1;
> clip currentpicture to screen;
> \stopMPcode
> \stoptext
>
> Are there any routines with Metafun to improve this code?

define 'improve' .. anyway:

\starttext
\startMPpage
     numeric xmin, xmax, ymin, ymax;
     xmin := -2.5; xmax := 2.5; ymax :=2.5 ;ymin:=-2.5; u := 2cm;
     pickup pencircle scaled 1pt ;
     drawarrow ((xmin,0) -- (xmax,0)) scaled u;
     drawarrow ((0,ymin) -- (0,ymax)) scaled u;
     draw tightfunction ("x", "-x*x+1", xmin, xmax, (xmax-xmin)/10) 
scaled u;
     setbounds currentpicture to boundingbox (((xmin,ymin) -- 
(xmax,ymax)) scaled u);
\stopMPpage
\stoptext

I'm sure that Alan can tell you how to use the new built-in 
interpolators,  their pros and cons in this case.

Hans

ps. A step of 0.001 is not needed here and gives a pretty large path.

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list