diff options
Diffstat (limited to 'macros/latex/contrib/profcollege/latex/PfCPixelArt.tex')
-rw-r--r-- | macros/latex/contrib/profcollege/latex/PfCPixelArt.tex | 216 |
1 files changed, 189 insertions, 27 deletions
diff --git a/macros/latex/contrib/profcollege/latex/PfCPixelArt.tex b/macros/latex/contrib/profcollege/latex/PfCPixelArt.tex index 77eecfcb42..503e2e1182 100644 --- a/macros/latex/contrib/profcollege/latex/PfCPixelArt.tex +++ b/macros/latex/contrib/profcollege/latex/PfCPixelArt.tex @@ -1,11 +1,16 @@ %%% % PixelArt %%% +\def\filedatePixelArt{2024/08/04}% +\def\fileversionPixelArt{0.1}% +\message{-- \filedatePixelArt\space v\fileversionPixelArt}% +% \newtoks\toklistePANombre% \def\UpdatetoksPANombre#1\nil{\addtotok\toklistePANombre{"#1",}}% -\setKVdefault[ClesPixelArt]{Largeur=29,Hauteur=29,Solution=false,Lettres=ABCDEFGHIJK,Nombres=false,ListeCouleurs={Orange,Red,LightGray,Maroon,Purple,black,black,Plum,Orange,White,White},Unite=5mm,Geant=false,HauteurD=1,LargeurD=1,Complet=false,Numero=1,Separations=false}% +\setKVdefault[ClesPixelArt]{Largeur=29,Hauteur=29,Solution=false,Lettres=ABCDEFGHIJK,Nombres=false,ListeCouleurs={Orange,Red,LightGray,Maroon,Purple,black,black,Plum,Orange,White,White},Unite=5mm,Geant=false,HauteurD=1,LargeurD=1,Complet=false,Numero=1,Separations=false,Deforme=false,Coefx=0.25,Coefy=0.25,Borne=false,Graines=false}% \defKV[ClesPixelArt]{ListeNombres=\setKV[ClesPixelArt]{Nombres}}% +\defKV[ClesPixelArt]{Graine=\setKV[ClesPixelArt]{Graines}}% \NewDocumentCommand\PixelArt{o m}{% \toklistePANombre{}% @@ -26,17 +31,23 @@ }% }% }{% - \quotient{\fpeval{\useKV[ClesPixelArt]{Numero}-1}}{\fpeval{\useKV[ClesPixelArt]{Hauteur}/\useKV[ClesPixelArt]{HauteurD}}}% - \modulo{\fpeval{\useKV[ClesPixelArt]{Numero}-1}}{\fpeval{\useKV[ClesPixelArt]{Hauteur}/\useKV[ClesPixelArt]{HauteurD}}}% -% quotient = \the\intquotient -- remainder = \the\remainder : +% \quotient{\fpeval{\useKV[ClesPixelArt]{Numero}-1}}{\fpeval{\useKV[ClesPixelArt]{Hauteur}/\useKV[ClesPixelArt]{HauteurD}}}% +% \modulo{\fpeval{\useKV[ClesPixelArt]{Numero}-1}}{\fpeval{\useKV[ClesPixelArt]{Hauteur}/\useKV[ClesPixelArt]{HauteurD}}}% + \quotient{\fpeval{\useKV[ClesPixelArt]{Numero}-1}}{\fpeval{\useKV[ClesPixelArt]{Largeur}/\useKV[ClesPixelArt]{LargeurD}}}% + \modulo{\fpeval{\useKV[ClesPixelArt]{Numero}-1}}{\fpeval{\useKV[ClesPixelArt]{Largeur}/\useKV[ClesPixelArt]{LargeurD}}}% +% quotient = \the\intquotient -- remainder = \the\remainder :\\ \BuildPixelArtGeant{#2}{\useKV[ClesPixelArt]{Lettres}}{\ListeAvantCouleurs}{\the\toklistePANombre}{\the\intquotient}{\the\remainder}% }% }{% - \BuildPixelArt{#2}{\useKV[ClesPixelArt]{Lettres}}{\ListeAvantCouleurs}{\the\toklistePANombre}% + \ifboolKV[ClesPixelArt]{Deforme}{% + \BuildPixelArtDeforme{#2}{\useKV[ClesPixelArt]{Lettres}}{\ListeAvantCouleurs}{\the\toklistePANombre}% + }{% + \BuildPixelArt{#2}{\useKV[ClesPixelArt]{Lettres}}{\ListeAvantCouleurs}{\the\toklistePANombre}% + }% }% }% -\NewDocumentCommand\BuildPixelArt{m m m m}{% +\NewDocumentCommand\BuildPixelArtDeforme{m m m m}{% \ifluatex \mplibforcehmode \begin{mplibcode} @@ -46,6 +57,39 @@ hauteurd:=\useKV[ClesPixelArt]{HauteurD}; Unite:=\useKV[ClesPixelArt]{Unite}; + %Deformation + Coefx=\useKV[ClesPixelArt]{Coefx}; + Coefy=\useKV[ClesPixelArt]{Coefy}; + boolean Borne,Graines; + Borne=\useKV[ClesPixelArt]{Borne}; + Graines=\useKV[ClesPixelArt]{Graines}; + if Graines: + randomseed:=\useKV[ClesPixelArt]{Graine}; + fi; + % + pair M[][]; + for l=1 upto hauteur+1: + for c=1 upto largeur+1: + if Borne: + if (l=1) or (l=hauteur+1): + M[l][c]=Unite*(c,l)+Unite*(-Coefx+uniformdeviate(2*Coefx),0); + if (c=1) or (c=largeur+1): + M[l][c]:=Unite*(c,l); + fi; + else: + if (c=1) or (c=largeur+1): + M[l][c]=Unite*(c,l-1)+Unite*(0,uniformdeviate(Coefy)); + else: + M[l][c]=Unite*(c,l)+Unite*(-Coefx+uniformdeviate(2*Coefx),-Coefy+uniformdeviate(2*Coefy)); + fi; + fi; + else: + M[l][c]=Unite*(c,l)+Unite*(-Coefx+uniformdeviate(2*Coefx),-Coefy+uniformdeviate(2*Coefy)); + fi; + %dotlabel("",M[l][c]); + endfor; + endfor; + boolean Solution,Nombres,Separations; Solution:=\useKV[ClesPixelArt]{Solution}; Nombres:=\useKV[ClesPixelArt]{Nombres}; @@ -54,7 +98,7 @@ string BaseLettres; BaseLettres=str #2; numeric EchelleScale; - EchelleScale=Unite/5mm; + EchelleScale=Unite/10mm; color ColorEntier[],ColFond; n:=0; @@ -84,11 +128,107 @@ if Nombres: for m=0 upto (length BaseLettres-1): if (substring(p,p+1) of p_)=substring(m,m+1) of BaseLettres: - label(TEX(RetiensNombres[m+1]) scaled EchelleScale,((l-1)*Unite,(h-1)*Unite)); + label(TEX(RetiensNombres[m+1]) scaled EchelleScale,iso(M[h+1][l],M[h][l],M[h][l+1],M[h+1][l+1])); fi; endfor; else: - label(TEX(substring(p,p+1) of p_) scaled EchelleScale,((l-1)*Unite,(h-1)*Unite)); + label(TEX(substring(p,p+1) of p_) scaled EchelleScale,iso(M[h+1][l],M[h][l],M[h][l+1],M[h+1][l+1])); + fi; + if Solution: + for m=0 upto (length BaseLettres-1): + if (substring(p,p+1) of p_)=substring(m,m+1) of BaseLettres: + ColFond:=ColorEntier[m+1]; + fi; + endfor; + if unknown ColFond: else: fill polygone(M[h+1][l],M[h][l],M[h][l+1],M[h+1][l+1]) withcolor ColFond fi; + fi; + trace polygone(M[h+1][l],M[h][l],M[h][l+1],M[h+1][l+1]); + fi; + endfor; + endfor; + closefrom nomfichier; + enddef; + + Lecturecsv("#1"); +% if Separations: +% drawoptions(withcolor Purple); +% for k=hauteur step -hauteurd until 0: +% draw (Unite*(-1,k-0.5)--Unite*(largeur,k-0.5)) withpen pencircle scaled 1.25; +% endfor; +% for k=0 step largeurd until largeur: +% draw (Unite*(k-0.5,hauteur+0.125)--Unite*(k-0.5,-0.875)) withpen pencircle scaled 1.25; +% endfor; +% drawoptions(); +% fi; + \end{mplibcode} +\fi +}% + +\NewDocumentCommand\BuildPixelArt{m m m m}{% + \ifluatex + \mplibforcehmode + \begin{mplibcode} + largeur:=\useKV[ClesPixelArt]{Largeur}; + hauteur:=\useKV[ClesPixelArt]{Hauteur}; + largeurd:=\useKV[ClesPixelArt]{LargeurD}; + hauteurd:=\useKV[ClesPixelArt]{HauteurD}; + Unite:=\useKV[ClesPixelArt]{Unite}; + + boolean Solution,Nombres,Separations; + Solution:=\useKV[ClesPixelArt]{Solution}; + Nombres:=\useKV[ClesPixelArt]{Nombres}; + Separations:=\useKV[ClesPixelArt]{Separations}; + + string BaseLettres; + BaseLettres=str #2; + numeric EchelleScale; + EchelleScale=Unite/5mm; + + color ColorEntier[],ColFond; + n:=0; + for p_=#3: + n:=n+1; + ColorEntier[n]:=p_; + endfor; + + string RetiensNombres[]; + if Nombres: + k:=0; + for p_=#4: + k:=k+1; + RetiensNombres[k]=p_; + endfor; + else: + m:=0; + for p_=0 upto n-1: + m:=m+1; + RetiensNombres[m]=substring(p_,p_+1) of BaseLettres; + endfor; + fi; + + picture Etiquette[]; + for k=1 upto n: + Etiquette[k]=image( + label(TEX(RetiensNombres[k]) scaled EchelleScale,(0,0)); + ); + endfor; + + vardef Lecturecsv(expr nomfichier)= + for h=hauteur downto 1: + string p_; + p_=readfrom nomfichier; + l:=0; + for p=0 step 2 until 2*largeur-2: + l:=l+1; + if Solution=false: + if (substring(p,p+1) of p_)="-": + else: + for m=0 upto (length BaseLettres-1): + if (substring(p,p+1) of p_)=substring(m,m+1) of BaseLettres: + draw Etiquette[m+1] shifted((l-1)*Unite,(h-1)*Unite); + fi; + endfor; + fi; fi; if Solution: for m=0 upto (length BaseLettres-1): @@ -99,7 +239,6 @@ if unknown ColFond: else: fill (unitsquare scaled Unite) shifted ((l-1)*Unite-0.5*Unite,(h-1)*Unite-0.5*Unite) withcolor ColFond fi; fi; trace (unitsquare scaled Unite) shifted ((l-1)*Unite-0.5*Unite,(h-1)*Unite-0.5*Unite); - fi; endfor; endfor; closefrom nomfichier; @@ -118,10 +257,12 @@ fi; \end{mplibcode} \else - \begin{mpost}[mpsettings={largeur:=\useKV[ClesPixelArt]{Largeur}; hauteur:=\useKV[ClesPixelArt]{Hauteur}; Unite:=\useKV[ClesPixelArt]{Unite}; boolean Solution,Nombres; Solution:=\useKV[ClesPixelArt]{Solution}; Nombres:=\useKV[ClesPixelArt]{Nombres};}] + \begin{mpost}[mpsettings={largeur:=\useKV[ClesPixelArt]{Largeur}; hauteur:=\useKV[ClesPixelArt]{Hauteur}; Unite:=\useKV[ClesPixelArt]{Unite}; boolean Solution,Nombres,Separations; Solution:=\useKV[ClesPixelArt]{Solution}; Nombres:=\useKV[ClesPixelArt]{Nombres}; Separations:=\useKV[ClesPixelArt]{Separations};}] string BaseLettres; BaseLettres=str #2; - + numeric EchelleScale; + EchelleScale=Unite/5mm; + color ColorEntier[],ColFond; n:=0; for p_=#3: @@ -131,13 +272,26 @@ string RetiensNombres[]; if Nombres: - n:=0; + k:=0; for p_=#4: - n:=n+1; - RetiensNombres[n]=p_; + k:=k+1; + RetiensNombres[k]=p_; + endfor; + else: + m:=0; + for p_=0 upto n-1: + m:=m+1; + RetiensNombres[m]=substring(p_,p_+1) of BaseLettres; endfor; fi; - + + picture Etiquette[]; + for k=1 upto n: + Etiquette[k]=image( + label(LATEX(RetiensNombres[k]) scaled EchelleScale,(0,0)); + ); + endfor; + vardef Lecturecsv(expr nomfichier)= for h=hauteur downto 1: string p_; @@ -145,16 +299,15 @@ l:=0; for p=0 step 2 until 2*largeur-2: l:=l+1; + if Solution=false: if (substring(p,p+1) of p_)="-": else: - if Nombres: for m=0 upto (length BaseLettres-1): if (substring(p,p+1) of p_)=substring(m,m+1) of BaseLettres: - label(LATEX(RetiensNombres[m+1]),((l-1)*Unite,(h-1)*Unite)); + draw Etiquette[m+1] shifted((l-1)*Unite,(h-1)*Unite); fi; endfor; - else: - label(LATEX(substring(p,p+1) of p_),((l-1)*Unite,(h-1)*Unite)); + fi; fi; if Solution: for m=0 upto (length BaseLettres-1): @@ -165,21 +318,30 @@ if unknown ColFond: else: fill (unitsquare scaled Unite) shifted ((l-1)*Unite-0.5*Unite,(h-1)*Unite-0.5*Unite) withcolor ColFond fi; fi; trace (unitsquare scaled Unite) shifted ((l-1)*Unite-0.5*Unite,(h-1)*Unite-0.5*Unite); - fi; endfor; endfor; closefrom nomfichier; enddef; Lecturecsv("#1"); + if Separations: + drawoptions(withcolor Purple); + for k=hauteur step -hauteurd until 0: + draw (Unite*(-1,k-0.5)--Unite*(largeur,k-0.5)) withpen pencircle scaled 1.25; + endfor; + for k=0 step largeurd until largeur: + draw (Unite*(k-0.5,hauteur+0.125)--Unite*(k-0.5,-0.875)) withpen pencircle scaled 1.25; + endfor; + drawoptions(); + fi; \end{mpost} \fi -} +}% \NewDocumentCommand\BuildPixelArtGeant{m m m m m m}{% - \ifluatex - \mplibforcehmode - \begin{mplibcode} + \ifluatex% + \mplibforcehmode% + \begin{mplibcode}% largeur:=\useKV[ClesPixelArt]{Largeur}; hauteur:=\useKV[ClesPixelArt]{Hauteur}; largeurd:=\useKV[ClesPixelArt]{LargeurD}; @@ -251,5 +413,5 @@ Lecturecsv("#1"); \end{mplibcode} - \fi -}
\ No newline at end of file + \fi% +}%
\ No newline at end of file |