

\starttext





\startMPcode



path Cb[];



vardef courbe[](expr a,b,nb)(text texte)=

 path $;

 for i:=0 upto nb :

 x@[i]:=(a+i*(b-a)/nb);

 x:=x@[i];

 y@[i]:=texte;

 endfor ;

 Cb@:=(x@.0*x.u,y@.0*y.u)

 for i:=1 upto nb :

   ..(x@[i]*x.u,y@[i]*y.u)

 endfor;

 Cb@:=Cb@ shifted (z.origine*cm);

 $=Cb@;

$

enddef;



vardef cadre(expr q,r)=

  z.so=q;

  z.ne=r;

  path limite;

  limite:=z.so*cm--(x.ne*cm,y.so*cm)--z.ne*cm--(x.so*cm,y.ne*cm)--cycle;

  extra_endfig := "clip currentpicture to limite;" & extra_endfig;

enddef;

vardef origine(expr p)=

  x.origine=xpart(p);

  y.origine=ypart(p);

enddef;

vardef unites(expr q,r)=

  x.u:=q*cm;

  y.u:=r*cm;

enddef;





vardef depart(expr q,r,p,s,t)=

  cadre(q,r);

  origine(p);

  unites(s,t);

enddef;



vardef origine(expr p)=

  x.origine=xpart(p);

  y.origine=ypart(p);

enddef;



vardef unites(expr q,r)=

  x.u:=q*cm;

  y.u:=r*cm;

enddef;



vardef curvelabel@\#(expr a)(suffix pos)=

  save se;

  picture se;

  numeric t;

%show a;

  pair pp,tangent;

  if str pos ="" :

    t:=0.5*length Cb@\#

  else :

    t:=pos*length Cb@\#;

%show t;

  fi;

  pp:=point t of Cb@\#;

  tangent:=unitvector(direction t of Cb@\#);

  se=image(

    label(a rotated angle(tangent), pp+2mm*(tangent rotated 90));

    );

  se

enddef;





depart((-3,-3.5),(2.5,3.5),(0,0),2,2);

draw courbe1(-1,1,100,x*x) withcolor blue;

draw curvelabel1(btex $x^2$ etex, 0.9);



\stopMPcode





\stoptext

