ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* reusing metapost graphics
@ 2003-03-20  6:26 Matthew Huggett
  2003-03-20  8:53 ` scaling " Patrick Gundlach
  2003-03-20  9:40 ` reusing " Hans Hagen
  0 siblings, 2 replies; 7+ messages in thread
From: Matthew Huggett @ 2003-03-20  6:26 UTC (permalink / raw)


Hi:

I'm designing a year's worth of English lessons for some Japanese kids, 
and I'm using Metapost and ConTeXt to generate flashcards for vocabulary 
training.  I have a few questions:
(1) I want to keep my Metapost figures defined in a ConTeXt environment 
file so that I can recall them as I need in future lessons.  Is there 
anything wrong with this approach?
(2) How do I make a Metapost figure defined in a ConTeXt file reusable? 
 Do I need to wrap the definition of the figure in a macro so that the 
figure is recreated everytime I need it?
(3) With \useMPgraphic, is there any mechanism to scale the image as 
with \useexternalfigure?

If this is all in the documentation, I apologize.  (I would appreciate a 
pointer to the documentation though :-) )

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

* scaling metapost graphics
  2003-03-20  6:26 reusing metapost graphics Matthew Huggett
@ 2003-03-20  8:53 ` Patrick Gundlach
  2003-03-20  9:40 ` reusing " Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Patrick Gundlach @ 2003-03-20  8:53 UTC (permalink / raw)


Matthew Huggett <mhuggett@zam.att.ne.jp> writes:

Hello,

let's start with #3

> (3) With \useMPgraphic, is there any mechanism to scale the image as
>     with \useexternalfigure?


\placefigure [right]{none}{\scale[sx=.6,sy=.6]{\useMPgraphic{....}}}


> If this is all in the documentation, I apologize.  (I would appreciate
> a pointer to the documentation though :-) )

it is somewhere I guess ;-)

Patrick

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

* Re: reusing metapost graphics
  2003-03-20  6:26 reusing metapost graphics Matthew Huggett
  2003-03-20  8:53 ` scaling " Patrick Gundlach
@ 2003-03-20  9:40 ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2003-03-20  9:40 UTC (permalink / raw)


At 03:26 PM 3/20/2003 +0900, you wrote:
>Hi:
>
>I'm designing a year's worth of English lessons for some Japanese kids, 
>and I'm using Metapost and ConTeXt to generate flashcards for vocabulary 
>training.  I have a few questions:
>(1) I want to keep my Metapost figures defined in a ConTeXt environment 
>file so that I can recall them as I need in future lessons.  Is there 
>anything wrong with this approach?

sounds ok to me

>(2) How do I make a Metapost figure defined in a ConTeXt file reusable? Do 
>I need to wrap the definition of the figure in a macro so that the figure 
>is recreated everytime I need it?

see patricks answer; in addition to that: external figures are reused by 
default

\startreusableMPgraphic{abc}

\stopreusableMPgraphic

\placefigure{]{\reuseMPgraphic{abc}}

will also be reused

>(3) With \useMPgraphic, is there any mechanism to scale the image as with 
>\useexternalfigure?

see patricks answer

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------

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

* Re: scaling Metapost graphics
  2000-11-28 21:18 scaling Metapost graphics David Arnold
  2000-11-28 22:01 ` Johannes H?sing
@ 2000-11-29  8:59 ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2000-11-29  8:59 UTC (permalink / raw)
  Cc: johannes.huesing, ntg-context

At 01:18 PM 11/28/00 -0800, David Arnold wrote:
>Johannes,
>
>Hans will help you with the Context way, if there is one. What I like to do
>is get the graphics the right size before I use them. I always use a
>scaling factor in my MP code. For example, let's say I want a figure that
>is 3 inches wide.

You can also scale the picture afterwards, using 'xsized' and alike [see
manual]. I think that david's method is okay, since that way you get the
dimensions you ask for while retaining the line widths etc. This is best
for consistency. 

Hans 
-------------------------------------------------------------------------
                                                  Hans Hagen | PRAGMA ADE
                      Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------


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

* Re: scaling Metapost graphics
  2000-11-28 21:18 scaling Metapost graphics David Arnold
@ 2000-11-28 22:01 ` Johannes H?sing
  2000-11-29  8:59 ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Johannes H?sing @ 2000-11-28 22:01 UTC (permalink / raw)


On Tue, Nov 28, 2000 at 01:18:53PM -0800, David Arnold wrote:
> Johannes,
> 
> Hans will help you with the Context way, if there is one. What I like to do
> is get the graphics the right size before I use them. I always use a
> scaling factor in my MP code. For example, let's say I want a figure that
> is 3 inches wide.
> 
> %initialize scale
> numeric u; 5u=3in;
> 
[...]
> 
> Note that this is exactly 3inches wide. Now, suppose I change my mind and I
> want it to be 4inches wide. This is all I have to do:
> 
> %initialize scale
> numeric u; 5u=4in;
> 

David, 

this is a good idea and I think I'll incorporate this style!

Greetings

Johannes
-- 
Johannes Hüsing <hannes@ruhrau.de>   /"\  ASCII-Ribbon Campaign
                                     \ /  against HTML
                                      X   in e-mail and news
                                     / \


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

* Re: scaling Metapost graphics
@ 2000-11-28 21:18 David Arnold
  2000-11-28 22:01 ` Johannes H?sing
  2000-11-29  8:59 ` Hans Hagen
  0 siblings, 2 replies; 7+ messages in thread
From: David Arnold @ 2000-11-28 21:18 UTC (permalink / raw)
  Cc: ntg-context

[-- Attachment #1: Type: text/plain, Size: 1536 bytes --]

Johannes,

Hans will help you with the Context way, if there is one. What I like to do
is get the graphics the right size before I use them. I always use a
scaling factor in my MP code. For example, let's say I want a figure that
is 3 inches wide.

%initialize scale
numeric u; 5u=3in;

%initialize points
pair A, B, C, D, E;
A:=origin;
B:=(3u,0);
C:=(5u,0);
D:=(5u,3u);
E:=(0,5u);

%draw frame
draw A--B--C--D--B--E--cycle;

Note that this is exactly 3inches wide. Now, suppose I change my mind and I
want it to be 4inches wide. This is all I have to do:

%initialize scale
numeric u; 5u=4in;

%initialize points
pair A, B, C, D, E;
A:=origin;
B:=(3u,0);
C:=(5u,0);
D:=(5u,3u);
E:=(0,5u);

%draw frame
draw A--B--C--D--B--E--cycle;

Notice that nothing changes save my scaling factor. So, good advance
planning is a savior. I've attached some more code where you can see this
in action.

At 10:06 PM 11/28/00 +0100, you wrote:
>Hi all,
>In the beginner's book it says that \useexternalfigure can go with the
>option height=, width=. Obviously, \useMPgraphics does not provide
>such an option (at least it would print out the option as plain
>text). So what is the ConTeXt way to include MP graphics and scale
>them?
>
>Groetjes
>
>
>Johannes
>-- 
>Johannes Hüsing <hannes@ruhrau.de>   /"\  ASCII-Ribbon Campaign
>                                     \ /  against HTML
>                                      X   in e-mail and news
>                                     / \
>
>

[-- Attachment #2: pretest.mp --]
[-- Type: text/plain, Size: 14085 bytes --]

input mp-tool;

%prologues:=0;

%pi
numeric pi;
pi:=3.14159;

%cos function for radian input
def cos(expr x)=
 cosd(180/pi*x)
enddef;

%sin function for radian input
def sin(expr x)=
 sind(180/pi*x)
enddef;

%xtick marks
def xtick(expr p)=
 draw ((0,-2pt)--(0,2pt)) shifted p;
enddef;

%ytick marks
def ytick(expr p)=
 draw ((-2pt,0)--(2pt,0)) shifted p;
enddef;

%opendot
vardef open(expr pos)=
 path p;
 p:=fullcircle scaled 3pt;
 p:=p shifted pos;
 fill p withcolor white;
 draw p withcolor red;
enddef;

beginfig(1);

%Define function to be drawn
def f(expr x)=
 x*(x+2)*(x-2)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(xmin,f(xmin));
for x=xmin step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%Clip function path
draw p;
clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic withcolor blue;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

endfig;

beginfig(2);

%Define function to be drawn
def f(expr x)=
 x*(x+2)*(x-2)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(xmin,f(xmin));
for x=xmin step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%Clip function path
draw p withcolor blue;

%Highlight parts of the path that are above the axis
p:=(-2,f(-2));
for x = -2 step dx until 0:
 p:=p--(x,f(x));
endfor;
p:=p--(0,f(0));
p:=p xscaled ux yscaled uy;
draw p withcolor red withpen pencircle scaled 1pt;

p:=(2,f(2));
for x = 2 step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));
p:=p xscaled ux yscaled uy;
draw p withcolor red withpen pencircle scaled 1pt;

%Draw open circles
open((-2*ux,0));
open((0,0));
open((2*ux,0));

clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

endfig;

beginfig(3);

%Define function to be drawn
def f(expr x)=
 exp(x)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(xmin,f(xmin));
for x=xmin step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%Clip function path
draw p withcolor blue;

%reflect p about x-axis
draw (p reflectedabout ((0,0),(1,0))) withcolor red;

clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

%label first curve
label.rt(btex $y=e^x$ etex, (2ux,5uy));

%label second curve
label.rt(btex $y=e^{-x}$ etex, (2ux,-5uy));

endfig;

beginfig(4);

%Define function to be drawn
def f(expr x)=
 exp(x)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(xmin,f(xmin));
for x=xmin step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%Clip function path
draw p reflectedabout ((0,0),(1,0)) shifted (0,1uy) withcolor blue;

clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

%ytick marks
for k=xmin step 1 until xmax:
 ytick((0,k*uy))
endfor;

%label xticks
label.lft(btex $-5$ etex, (0,ymin*uy));
label.lft(btex $5$ etex, (0,ymax*uy));

%draw in the asymptote
draw (xmin*ux,1uy)--(xmax*ux,1uy) withcolor red dashed evenly;

endfig;

beginfig(5);

%Define function to be drawn
def f(expr x)=
 ln(x-2)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(2.01,f(2.01));
for x=2.01 step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%draw the function
draw p withcolor blue;

%clip
clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

%draw the asymptote
draw (2ux,ymin*uy)--(2ux,ymax*uy) dashed evenly withcolor red;

%plot key point
drawdot (3ux,0) withpen pencircle scaled 2pt;

%label key point
pic:=thelabel.ulft(btex $(3,0)$ etex, (3ux,0));
unfill bbox pic;
draw pic;

endfig;

beginfig(6);

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

%draw axes
path xaxis,yaxis;
xaxis:=(-5u,0)--(5u,0);
yaxis:=(0,-5u)--(0,5u);
drawdblarrow xaxis scaled 1.1;
drawdblarrow yaxis scaled 1.1;
label.rt(btex $x$ etex, (1.1*u*xmax,0));
label.top(btex $y$ etex, (0,1.1*u*ymax));

%tickmarks
for k=-5u step 1u until 5u:
 xtick((k,0));
 ytick((0,k));
endfor;

%define and plot ellipse
path p;
p:=fullcircle xscaled 2u yscaled 6u;
draw p shifted (1u,-2u) withcolor blue;

%Label the center
drawdot (1u,-2u) withpen pencircle scaled 2pt;

%direction of motion
drawarrow (2u,-2u)--((2u,-2u)+10*down) withpen pencircle scaled 1pt withcolor red;

endfig;

beginfig(7);

%Define function to be drawn
def f(expr x)=
 sqrt(x)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(0,f(0));
for x=0 step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%draw the function
draw p withcolor blue;

%reflect the function across x-axis
draw p reflectedabout ((0,0),(1,0)) withcolor red;

%clip
clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%label the graphs
label.top(btex $y=\sqrt{x}$ etex, (5ux,3uy));
label.bot(btex $y=-\sqrt{x}$ etex, (5ux,-3uy));

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

%ytick marks
for k=xmin step 1 until xmax:
 ytick((0,k*ux))
endfor;

%label xticks
label.lft(btex $-5$ etex, (0,ymin*ux));
label.lft(btex $5$ etex, (0,ymax*ux));

endfig;

beginfig(8);

%Define function to be drawn
def f(expr x)=
 -sqrt(x+2)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(-2,f(-2));
for x=-2 step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%draw the function
draw p withcolor blue;

%clip
clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

%ytick marks
for k=xmin step 1 until xmax:
 ytick((0,k*ux))
endfor;

%label xticks
label.lft(btex $-5$ etex, (0,ymin*ux));
label.lft(btex $5$ etex, (0,ymax*ux));

endfig;

beginfig(9);

%Define function to be drawn
def f(expr x)=
 -sqrt(x+2)
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=-5;
xmax=5;
ymin=-5;
ymax=5;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=2in;
(ymax-ymin)*uy=2in;

%Declare and initialize clipping boundary
path q;
q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle;
q:=q xscaled ux yscaled uy;

%Declare and initialize number of plotted points
numeric N;
N:=200;

%Declare and calculate plotting increment delta x
numeric dx;
dx:=(xmax-xmin)/N;

%Declare and create function path
path p;
p:=(-2,f(-2));
for x=-2 step dx until xmax:
 p:=p--(x,f(x));
endfor;
p:=p--(xmax,f(xmax));

%Scale function path
p:=p xscaled ux yscaled uy;

%draw the function
draw p withcolor blue;

%draw the line y=x
draw (-5u,-5u)--(5u,5u) withcolor black;

%draw the reflection
draw p reflectedabout ((0,0),(1,1)) withcolor red;

%clip
clip currentpicture to q;

%Save and clear the function path
picture pic;
pic:=currentpicture;
clearit;

%Draw and label coordinate axes
drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0);
label.rt(btex $x$ etex,(1.1xmax*ux,0));
drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy);
label.top(btex $y$ etex,(0,1.1ymax*uy));

%Superimpose function plot
draw pic;

%xtick marks
for k=xmin step 1 until xmax:
 xtick((k*ux,0))
endfor;

%label xticks
label.bot(btex $-5$ etex, (xmin*ux,0));
label.bot(btex $5$ etex, (xmax*ux,0));

%ytick marks
for k=xmin step 1 until xmax:
 ytick((0,k*ux))
endfor;

%label xticks
label.lft(btex $-5$ etex, (0,ymin*ux));
label.lft(btex $5$ etex, (0,ymax*ux));

%Label f
label.bot(btex $f$ etex, (5ux,-3uy));

%label f^-1
label.lft(btex $f^{-1}$ etex, (-3ux,5uy));

%label y=x
label.urt(btex $y=x$ etex, (5u,5u));

endfig;

beginfig(10);

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

%axes
drawdblarrow (-3.1u,0)--(7.1u,0);
drawdblarrow (0,-5.1u)--(0,5.1u);

endfig;

end

[-- Attachment #3: Type: text/plain, Size: 292 bytes --]

-
David Arnold
College of the Redwoods
Mathematics Department
7351 Tompkins Hill Rd
Eureka, CA 95501
(707) 476-4222 Office
(707) 476-4424 Fax
http://online.redwoods.cc.ca.us/instruct/darnold/

Ordinary Differential Equations Using MATLAB, 2/e
http://www.prenhall.com/books/esm_0130113816.html

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

* scaling Metapost graphics
@ 2000-11-28 21:06 Johannes H?sing
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes H?sing @ 2000-11-28 21:06 UTC (permalink / raw)


Hi all,
In the beginner's book it says that \useexternalfigure can go with the
option height=, width=. Obviously, \useMPgraphics does not provide
such an option (at least it would print out the option as plain
text). So what is the ConTeXt way to include MP graphics and scale
them?

Groetjes

Johannes
-- 
Johannes Hüsing <hannes@ruhrau.de>   /"\  ASCII-Ribbon Campaign
                                     \ /  against HTML
                                      X   in e-mail and news
                                     / \


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

end of thread, other threads:[~2003-03-20  9:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-20  6:26 reusing metapost graphics Matthew Huggett
2003-03-20  8:53 ` scaling " Patrick Gundlach
2003-03-20  9:40 ` reusing " Hans Hagen
  -- strict thread matches above, loose matches on Subject: below --
2000-11-28 21:18 scaling Metapost graphics David Arnold
2000-11-28 22:01 ` Johannes H?sing
2000-11-29  8:59 ` Hans Hagen
2000-11-28 21:06 Johannes H?sing

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