summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/profcollege/PfCMosaique.tex
blob: 91936d597b1e6395e1ec3611ef9f10abe0076d8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%%%
% Mosaique
%%%
\setKVdefault[ClesMosaique]{Largeur=2,Hauteur=2,Solution=false,Type=1,Label,Echelle=1cm}

\newcommand\DessineMosaique[2][]{%
  \useKVdefault[ClesMosaique]%
  \setKV[ClesMosaique]{#1}%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}
    u:=\useKV[ClesMosaique]{Echelle};
    Type:=\useKV[ClesMosaique]{Type};
    input PfCMosaique;
    trace if Type=1:MosaiqueUn[#2] elseif Type=2: MosaiqueDeux[#2] fi;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={u:=\useKV[ClesMosaique]{Echelle};Type:=\useKV[ClesMosaique]{Type};}]%
    input PfCMosaique;
    trace if Type=1:MosaiqueUn[#2] elseif Type=2: MosaiqueDeux[#2] fi;
  \end{mpost}%
  \fi%
}%

\newcommand\DessineMosaiqueComplet[1]{%
  \ifluatex
  \mplibforcehmode
  \begin{mplibcode}
    input PfCMosaique;
    Largeur=\useKV[ClesMosaique]{Largeur};
    Hauteur=\useKV[ClesMosaique]{Hauteur};
    Type=\useKV[ClesMosaique]{Type};
    boolean Solution,Label;
    Solution=\useKV[ClesMosaique]{Solution};
    Label=\useKV[ClesMosaique]{Label};
    pair A,B,C,D;
    A=u*(0,1);
    B-A=u*(Largeur,0);
    C-B=u*(0,-Hauteur);
    D-C=A-B;
    picture mosaique;
    path case;
    case=unitsquare scaled 1cm;
    if Type=1:
    mosaique=image(
    trace case withcolor 0.5white;
    trace (point(0) of case)--(point(2) of case) withcolor 0.75white;
    trace (point(1) of case)--(point(3) of case) withcolor 0.75white;
    trace (point(0.5) of case)--(point(2.5) of case) withcolor 0.75white;
    trace (point(1.5) of case)--(point(3.5) of case) withcolor 0.75white;
    );
    else:
    mosaique=image(
    trace case withcolor 0.5white;
    trace (point(0.5) of case)--(point(2.5) of case) withcolor 0.75white;
    trace (point(1.5) of case)--(point(3.5) of case) withcolor 0.75white;
    trace (point(0.5) of case)--(point(1.5) of case)--(point(2.5) of case)--(point(3.5) of case)--cycle withcolor 0.75white;
    );
    fi;
    if Solution:
    nbmos:=0;
    for p_=#1:
    trace if Type=1:MosaiqueUn[xpart(p_)] else: MosaiqueDeux[xpart(p_)] fi shifted(u*(nbmos mod Largeur,-(nbmos div Largeur)));
    nbmos:=nbmos+1;
    endfor;
    else:
    nbmos:=0;
    for p_=#1:
    trace mosaique shifted(u*(nbmos mod Largeur,-(nbmos div Largeur)));
    if Label:
    label(TEX("\num{"&decimal(ypart(p_))&"}"),center (mosaique  shifted(u*(nbmos mod Largeur,-(nbmos div Largeur)))));
    fi;
    nbmos:=nbmos+1;
    endfor;
    fi;
    trace polygone(A,B,C,D);
  \end{mplibcode}
  \else
  \begin{mpost}[mpsettings={Largeur=\useKV[ClesMosaique]{Largeur};Hauteur=\useKV[ClesMosaique]{Hauteur};Type=\useKV[ClesMosaique]{Type};boolean Solution,Label;Solution=\useKV[ClesMosaique]{Solution};}]
    Label=\useKV[ClesMosaique]{Label};
    input PfCMosaique;
    pair A,B,C,D;
    A=u*(0,1);
    B-A=u*(Largeur,0);
    C-B=u*(0,-Hauteur);
    D-C=A-B;
    picture mosaique;
    path case;
    case=unitsquare scaled 1cm;
    if Type=1:
    mosaique=image(
    trace case withcolor 0.5white;
    trace (point(0) of case)--(point(2) of case) withcolor 0.75white;
    trace (point(1) of case)--(point(3) of case) withcolor 0.75white;
    trace (point(0.5) of case)--(point(2.5) of case) withcolor 0.75white;
    trace (point(1.5) of case)--(point(3.5) of case) withcolor 0.75white;
    );
    else:
    mosaique=image(
    trace case withcolor 0.5white;
    trace (point(0.5) of case)--(point(2.5) of case) withcolor 0.75white;
    trace (point(1.5) of case)--(point(3.5) of case) withcolor 0.75white;
    trace (point(0.5) of case)--(point(1.5) of case)--(point(2.5) of case)--(point(3.5) of case)--cycle withcolor 0.75white;
    );
    fi;
    if Solution:
    nbmos:=0;
    for p_=#1:
    trace if Type=1:MosaiqueUn[xpart(p_)] else: MosaiqueDeux[xpart(p_)] fi shifted(u*(nbmos mod Largeur,-(nbmos div Largeur)));
    nbmos:=nbmos+1;
    endfor;
    else:
    nbmos:=0;
    for p_=#1:
    trace mosaique shifted(u*(nbmos mod Largeur,-(nbmos div Largeur)));
    if Label:
    label(LATEX("\num{"&decimal(ypart(p_))&"}"),center (mosaique  shifted(u*(nbmos mod Largeur,-(nbmos div Largeur)))));
    fi;
    nbmos:=nbmos+1;
    endfor;
    fi;
    trace polygone(A,B,C,D);
  \end{mpost}
  \fi
}%
    
\newtoks\toklistecaseM%
\def\UpdatetoksMosaique#1/#2\nil{\addtotok\toklistecaseM{(#1,#2),}}%

\newcommand\Mosaique[2][]{%
  \useKVdefault[ClesMosaique]%
  \setKV[ClesMosaique]{#1}%
  \setsepchar[*]{,*/}%
  \readlist*\ListeMosaique{#2}%
  \toklistecaseM{}%
  \foreachitem\compteur\in\ListeMosaique{\expandafter\UpdatetoksMosaique\compteur\nil}%
  \DessineMosaiqueComplet{\the\toklistecaseM}%
}%