ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Metapost and Metafun
@ 2014-05-21 17:55 Fabrice Couvreur
  2014-05-21 18:21 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Fabrice Couvreur @ 2014-05-21 17:55 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 765 bytes --]

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?
thank you,
Fabrice

[-- Attachment #1.2: Type: text/html, Size: 1485 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Metapost and Metafun
  2014-05-21 17:55 Metapost and Metafun Fabrice Couvreur
@ 2014-05-21 18:21 ` Hans Hagen
  2014-05-21 21:06   ` Fabrice
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2014-05-21 18:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Alan BRASLAU

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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Metapost and Metafun
  2014-05-21 18:21 ` Hans Hagen
@ 2014-05-21 21:06   ` Fabrice
  0 siblings, 0 replies; 3+ messages in thread
From: Fabrice @ 2014-05-21 21:06 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 209 bytes --]

Hi Hans,
Thank you for the code that is cleaner and certainly less long!
Fabrice

PS : What do you mean by:
> define 'improve' .. anyway:

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


[-- Attachment #1.2: Type: text/html, Size: 1005 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2014-05-21 21:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-21 17:55 Metapost and Metafun Fabrice Couvreur
2014-05-21 18:21 ` Hans Hagen
2014-05-21 21:06   ` Fabrice

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