%%% % Fraction d'aire d'un carré %%% \setKVdefault[JeuAireCarre]{Couleur=LightSteelBlue,CouleurFond=Cornsilk,Perso=false,Graines=false,Parts=3,Longueur=4,NbPoints=2,Angle=0}% \defKV[JeuAireCarre]{Graine=\setKV[JeuAireCarre]{Graines}\PfCGraineAlea{#1}}% \defKV[JeuAireCarre]{ListeParts=\setKV[JeuAireCarre]{Perso}\xdef\PfCFooJeuAireCarre{#1}}% \NewDocumentCommand\FractionAireCarre{o}{% \useKVdefault[JeuAireCarre]% \setKV[JeuAireCarre]{#1}% \ifboolKV[JeuAireCarre]{Perso}{% \BuildJeuAireCarre{\PfCFooJeuAireCarre}% }{% \BuildJeuAireCarre{}% }% }% \def\BuildJeuAireCarreCode{% vardef ChoixParmiEntier(expr nentier,nbretiens)= numeric ListeInitiale[],ListeFinale[]; for l=1 upto nentier: ListeInitiale[l]=l; ListeIntermed[l]=l; endfor; maxx=nentier; for l=1 upto nbretiens: intermed:=ceiling(uniformdeviate(maxx)); ListeFinale[l]=ListeInitiale[intermed]; f:=0; for g=1 upto nentier: if g<>intermed: f:=f+1; ListeIntermed[f]:=ListeInitiale[g]; fi; endfor; maxx:=nentier-l; for h=1 upto maxx: ListeInitiale[h]:=ListeIntermed[h]; endfor; endfor; enddef; % On crée un Quick Sort def QS(expr ndeb,nfin)= begingroup save v,m,x; if ndeb2: ChoixParmiEntier(4*Parts-1,NbPoints); else: ChoixParmiEntier(3*Parts-1,NbPoints); fi; for k=1 upto NbPoints: cpt[k]=k; endfor; QS(1,NbPoints); for k=1 upto NbPoints: place:=ListeFinale[cpt[k]]; Base[k]=M[place]; endfor; else: PartsPerso(#1); fi; fill CarreSupport withcolor CouleurFond; fill Base0 for k=1 upto NbPoints:--Base[k] endfor --cycle withcolor Couleur; trace Base0 for k=1 upto NbPoints:--Base[k] endfor --cycle; trace CarreSupport; for k=0 upto (4*Parts): draw cercles(M[k],0.5mm); endfor; picture Retiens; Retiens=currentpicture; currentpicture:=nullpicture; trace rotation(Retiens,iso(A1,A3),Angle); \end{mplibcode} \else \begin{mpost}[mpsettings={\BuildJeuAireCarreCode}] if Perso=false: if NbPoints>2: ChoixParmiEntier(4*Parts-1,NbPoints); else: ChoixParmiEntier(3*Parts-1,NbPoints); fi; for k=1 upto NbPoints: cpt[k]=k; endfor; QS(1,NbPoints); for k=1 upto NbPoints: place:=ListeFinale[cpt[k]]; Base[k]=M[place]; endfor; else: PartsPerso(#1); fi; fill CarreSupport withcolor CouleurFond; fill Base0 for k=1 upto NbPoints:--Base[k] endfor --cycle withcolor Couleur; trace Base0 for k=1 upto NbPoints:--Base[k] endfor --cycle; trace CarreSupport; for k=0 upto (4*Parts): draw cercles(M[k],0.5mm); endfor; picture Retiens; Retiens=currentpicture; currentpicture:=nullpicture; trace rotation(Retiens,iso(A1,A3),Angle); \end{mpost} \fi }%