%@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);

%RESERVOiR Ep


beginfig(1);
  pair A[],B[],C[],D[]; path p,pp;
  
  A[0]=(0,0);
  A[1]=(10cm,0);
  A[2]=(13cm,4cm);
  A[3]=(3cm,4cm);

  for i=0 upto 3: B[i]:=A[i] shifted (0,2cm); endfor
  for i=0 upto 3: C[i]:=A[i] shifted (0,2.5cm); endfor
  for i=0 upto 3: D[i]:=A[i] shifted (0,3.5cm); endfor

  p:=C[0]--C[1]--C[2]--C[3]--cycle;
  pp:=B[0]--B[1]--B[2]--C[2]--C[1]--C[0]--cycle;
  
  fill p withcolor bleu_ciel;
  fill pp withcolor bleu_ciel;
  
  draw A[0]--A[1]--A[2];
  draw B[0]--B[1]--B[2] withcolor bleu_m withpen pencircle scaled 2bp;
  draw C[0]--C[1]--C[2] withcolor bleu_m withpen pencircle scaled 2bp;
  draw D[0]--D[1]--D[2]--D[3]--cycle;
  
  draw A[2]--A[3]--A[0] dashed evenly;
  draw B[2]--B[3]--B[0] withcolor bleu_m dashed evenly withpen pencircle scaled 2bp;
  draw C[2]--C[3]--C[0] withcolor bleu_m dashed evenly withpen pencircle scaled 2bp;
  
  draw A[0]--D[0];
  draw A[1]--D[1];
  draw A[2]--D[2];
  draw A[3]--D[3] dashed evenly;
  
  label.lft(btex $h_i$ etex scaled 1.5, B[0]);
  label.lft(btex $h_{i+1}$ etex scaled 1.5, C[0]);
  label.lft(btex $h_0=0$ etex scaled 1.5, A[0]);
  label.lft(btex $h_n=100$ etex scaled 1.5, D[0]);
endfig;
%SUBDIVISIon PLUs FINE 

vardef axes =
  drawarrow (ux*xmin,0) -- (ux*xmax,0); % axe des x
  drawarrow ((0,uy*ymin) -- (0,uy*ymax))  ; % axe des y
enddef;


beginfig(2);
% Déclarations des constantes %
  ux:=2.3cm; uy:=0.8cm;
  xmin:=-.5; xmax:=7;
  ymin:=xmin; ymax:=6;
  coefficient:=1; % coefficient d'échelle
  
%Tracé des axes
  axes;
  
  pair a,b,c,d,e,f,bb,cc,dd,ee,xa,xc,xf,cu,cd,ct,gu,gd,gt,gq;
  
  a=(ux,2.5*uy);
  b=(2*ux,4*uy);
  c=(3*ux,2*uy);
  d=(3.4*ux,1.2*uy);
  e=(4.5*ux,5*uy);
  f=(5*ux,3.5*uy);
  bb=b xscaled 0;
  cc=c xscaled 0;
  dd=d xscaled 0;
  ee=e xscaled 0;
  xa=a yscaled 0;
  xc=c yscaled 0;
  xf=f yscaled 0;
  cu=(ux,2*uy);
  cd=(ux,4*uy);
  ct=(3*ux,4*uy);
  gu=(ux,1.2*uy);
  gd=(5*ux,1.2*uy);
  gt=(5*ux,5*uy);
  gq=(ux,5*uy);

  path p,pp,ppp; 
  
  pp:=a..tension1.3..{dir 0}b{dir 0}..c..{dir 0}d{dir 0}..tension1.5..{dir 0}e{dir 0}..tension1.3..{dir300}f;
  p:=c--cu--cd--ct--cycle;
  ppp:=gu--gd--gt--gq--cycle;
  
  fill ppp withcolor bleu_ciel;
  fill p withcolor bleu_m;
  draw pp withpen pencircle scaled 1.5bp;
  
  dotlabel.top(btex $ $ etex,b);
  dotlabel.bot(btex $ $ etex,d);
  dotlabel.top(btex $ $ etex,e);
  dotlabel.urt(btex $ $ etex,c);
  
  label.lft(btex $M_i$ etex, ee);
  label.lft(btex $M'_i$ etex, bb);
  label.lft(btex $m'_i$ etex, cc);
  label.lft(btex $m_i$ etex, dd);
  
  label.bot(btex $a_i$ etex,xa);
  label.bot(btex $a'_i$ etex,xc);
  label.bot(btex $a_{i+1}$ etex,xf);
  
  draw ee--e dashed withdots withpen pencircle scaled 1.5bp;
  draw dd--d dashed withdots withpen pencircle scaled 1.5bp;
  draw f--xf dashed withdots withpen pencircle scaled 1.5bp;
  draw a--xa dashed withdots withpen pencircle scaled 1.5bp;
  draw bb--b dashed evenly withcolor bleu_m withpen pencircle scaled 1.3bp;
  draw cc--c--xc dashed evenly withcolor bleu_m withpen pencircle scaled 1.3bp;
endfig;
end