%@AUTEUR:Guillaume Connan
prologues:=2;

input courbes;
input geo;

color vert_e, turquoise, orange, vert_fonce, rose, vert_mer, bleu_ciel, or, rouge_v,bleu_m,bleu,bleu_f;
vert_e:=(0,0.790002,0.340007);
turquoise:=(0.250999,0.878399,0.815699);
orange:=(0.589999,0.269997,0.080004);
vert_fonce:=(0,1.4*0.392193,0);
rose:=(1.0, 0.752907, 0.796106);
bleu_ciel:=(1.2*0.529405,1.2*0.807794,1);%.2*0.921598);
or:=(1,0.843104,0);
rouge_v:=(0.829997,0.099994,0.119999);
bleu_m:=(0.7*0.529405,0.7*0.807794,0.7);%*0.921598);
bleu_f:=(0.211762,0.3231176,0.3686392);
bleu:=(0.529405,0.807794,1);

% Déclarations des constantes %
numeric xmin, xmax, ymin, ymax;

ux:=1cm; uy:=0.5cm; xmin := -0.5; xmax := 8;
ymin := xmin; ymax := xmax-1;

% Définitions des axes et labels associés
vardef axes =
  drawarrow (ux*xmin,0) -- (ux*xmax,0); % axe des x
  drawarrow (0,uy*ymin) -- (0,uy*ymax); % axe des y
  label.lrt(btex $x$ etex,(xmax*ux,0)); % label de l'axe des x
  label.urt(btex $y$ etex,(0,ymax*uy)); % label de l'axe des y
enddef;


beginfig(1);

  label.llft(btex $0$ etex,(0,0));

%Fonction, graphe

  vardef f(expr x) =2.3*sqrt(x) enddef;
  vardef h(expr x)=4*sqrt(x)-1.7 enddef;
  
  vardef tracee (suffix g)(expr a,b,inc) =
    save i; numeric i;
    for i=a step inc until b:
      (i*ux,f(i)*uy) ..
    endfor (b*ux,f(b)*uy)
  enddef;
  
  vardef traceh (suffix gg)(expr a,b,inc) =
    save i; numeric i;
    for i=a step inc until b:
      (i*ux,h(i)*uy) ..
    endfor (b*ux,h(b)*uy)
  enddef;

%Points sur le graphe
  pair A[],M[],O[],OO[],MM[];
  path z;
  u:=.7;%facteur d'échelle
  aa:=1.3;bb:=5;cc:=9;%numeros des points particuliers
  
  for i=1 upto 12: A[i]:=(i*u*ux,0);% A comme abscisse
    M[i]:=(i*u*ux,f(i*u)*uy); %M comme courbe !!
    O[i]:=(0,f(i*u)*uy); %O comme ordonnée
    OO[i]:=(0,h(i*u)*uy);
    MM[i]:=(i*u*ux,h(i*u)*uy);
  endfor ;
  
  z:=O[bb]--O[bb]shifted (xmax*ux,0)--O[bb]shifted (xmax*ux,0)shifted(0,(ymax-f(5*u))*uy)--O[bb]shifted(0,(ymax-f(5*u))*uy)--cycle;
  fill z withcolor bleu_ciel;
  axes;

  draw tracee(g,0,xmax,.1)withcolor bleu_f withpen pencircle scaled 1.5bp;
  draw traceh(gg,0,4.73,.1)withcolor 0.6white withpen pencircle scaled 1.5bp;
  
  draw M[bb] withpen pencircle scaled 6bp ;
  draw (aa*u*ux,f(aa*u)*uy) withpen pencircle scaled 6bp ;
  draw MM[bb] withpen pencircle scaled 6bp;

  draw A[bb]--M[bb]--O[bb] dashed evenly;
  
  draw (aa*u*ux,0)-- (aa*u*ux,f(aa*u)*uy)--(0,f(aa*u)*uy) dashed evenly;

  draw M[bb]--MM[bb]--OO[bb] dashed evenly;
  
  label.bot(btex $m$ etex,(aa*u*ux,0));
  label.bot(btex $M$ etex,A[bb]);
  
  label.lft(btex intersection éventuelle etex, (0,f(aa*u)*uy) shifted (0,.1*uy));
  label.lft(btex déjà au-dessus du seuil etex,OO[bb]  shifted (0,.2*uy));
  label.lrt(btex $y=f(x)$ etex,M[cc]) withcolor bleu_f;
  label.lrt(btex $y=g(x)$ etex,(4.73*ux,h(4.73)*uy))withcolor 0.6white;

%Tracé des droites

pair C,D;

C=O[bb]; %Point seuil
D=1/3(O[cc]+2O[cc-1]); %Point seuil

pickup pencircle scaled 2bp;

draw C--C  shifted (xmax*ux,0) withcolor bleu_m;

label.lft(btex Seuil etex,C shifted (0,-.1*uy));

endfig;

end