summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCRose.tex
blob: 2c8ff3fd069b6fe6c14694074ce22f0db0602a9f (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
%%%
% Rose
%%%
\setKVdefault[ClesRose]{Vide=false,Couleur=white,Produits=false,Solution=false,Rayon=2cm,Petales=7,Aide=false,FacteurMin=2,FacteurMax=10,ProduitVide=false,CaseVide=false,Polygone=false,Nom=Rose1}%

\NewDocumentCommand\RoseMul{o}{%
  \useKVdefault[ClesRose]%
  \setKV[ClesRose]{#1}%
  \ifluatex%
  \ifboolKV[ClesRose]{Solution}{%
    \DessineRoseMulSol%
  }{%
    \DessineRoseMul%
  }%
  \else%
  \DessineRoseMul%
  \fi%
}%

\newcommand\DessineRoseMulSol{%
  \ifluatex%
  \mplibforcehmode%
  \xdef\PfCNomRose{\useKV[ClesRose]{Nom}}%
  \begin{mplibcode}[\PfCNomRose]
    boolean Aide,Produits,Solution,Vide,ProduitVide,CaseVide,Polygone;
    Aide:=\useKV[ClesRose]{Aide};
    Vide:=\useKV[ClesRose]{Vide};
    Solution:=\useKV[ClesRose]{Solution};
    Produits:=\useKV[ClesRose]{Produits};
    ProduitVide:=\useKV[ClesRose]{ProduitVide};
    CaseVide:=\useKV[ClesRose]{CaseVide};
    if ProduitVide:Solution:=true fi;
    if CaseVide:Solution:=true fi;
    % on labelise
    if Vide=false:
    if Produits:
    else:
    for k=0 upto Petales-1:
    label(TEX("\num{"&decimal(Facteur[k])&"}"),(0.5[O,A[k]]-center BoiteRec));
    endfor;
    fi;
    if Produits or Solution:
    for k=0 upto Petales-1:
    label(TEX("\num{"&decimal(Produit[k])&"}"),(B[k]+0.5*Rayon*unitvector(B[k])));
    endfor;
    fi;
    fi;
    % On trace et on affiche...éventuellement :)
    if Aide:
    for k=0 upto Petales-1:
    drawarrow (0.5[O,A[k]]--1.75[O,B[k]]) cutbefore segment(A[k],A[k+1]) cutafter BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    drawarrow (0.5[O,A[k+1]]--1.75[O,B[k]]) cutbefore segment(A[k],A[k+1]) cutafter BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    endfor;
    fi;
    if ProduitVide:
    %choix=floor(uniformdeviate(Petales-1));
    fill (BoiteRec shifted (1.75[O,B[choix]]-center BoiteRec)) withcolor Fond;
    fill rotation(polygone(O,B0,A1,B1),O,(choix-1)*(360/Petales)) withcolor Fond;
    fill rotation(polygone(O,B0,A1,B1),O,choix*(360/Petales)) withcolor Fond;
    fi;
    if CaseVide:
    %choix:=floor(uniformdeviate(Petales-1));
    for k=0 upto Petales-1:
    if k<>choix:
    fill rotation(polygone(O,B0,A1,B1),O,k*(360/Petales)) withcolor Fond;
    fi;
    endfor;
    fi;
    trace A0 for k=1 upto Petales:--A[k] endfor --cycle;
    for k=0 upto Petales-1:
    trace segment(O,B[k]) dashed withdots scaled 0.25;
    draw BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    endfor;
  \end{mplibcode}
  \fi
}
\newcommand\DessineRoseMul{%
  \ifluatex%
  \mplibforcehmode%
  \xdef\PfCNomRose{\useKV[ClesRose]{Nom}}%
  \begin{mplibcode}[\PfCNomRose]
    vardef ExtraireListe(expr nbmin,nbmax,nbfacteurs)=
    numeric ElementE[],ElementS[];
    %% éléments d'entrée
    nbe:=1;
    for k=nbmin upto nbmax:
    ElementE[nbe]=k;
    nbe:=nbe+1;
    endfor;
    totalE:=(nbmax-nbmin)+1;
    numeric rec;
    for k=1 upto nbfacteurs:
    rec:=ceiling(uniformdeviate(totalE+1-k));
    ElementS[k]=ElementE[rec];
    numeric ElementI[];
    p:=0;
    for l=1 upto totalE+1-k:
    if l<>rec:
    p:=p+1;
    ElementI[p]=ElementE[l];
    fi;
    endfor;
    numeric ElementE[];
    for l=1 upto p:
    ElementE[l]=ElementI[l];
    endfor;
    endfor;
    enddef;
    pair A[],B[],O;
    Rayon:=\useKV[ClesRose]{Rayon};
    boolean Aide,Produits,Solution,Vide,ProduitVide,CaseVide,Polygone;
    Aide:=\useKV[ClesRose]{Aide};
    Vide:=\useKV[ClesRose]{Vide};
    Solution:=\useKV[ClesRose]{Solution};
    Produits:=\useKV[ClesRose]{Produits};
    ProduitVide:=\useKV[ClesRose]{ProduitVide};
    CaseVide:=\useKV[ClesRose]{CaseVide};
    if ProduitVide:Solution:=true fi;
    if CaseVide:Solution:=true fi;
    Polygone:=\useKV[ClesRose]{Polygone};
    Petales:=\useKV[ClesRose]{Petales};
    FacteurMin:=\useKV[ClesRose]{FacteurMin};
    FacteurMax:=\useKV[ClesRose]{FacteurMax};
    color Fond;
    Fond:=\useKV[ClesRose]{Couleur};
    O=(0,0);
    ExtraireListe(FacteurMin,FacteurMax,Petales);
    path cc;
    cc=cercles(O,Rayon);
    for k=0 upto Petales:
    A[k]=pointarc(cc,(360/Petales)*k);
    endfor;
    for k=0 upto Petales-1:
    B[k]=iso(A[k],A[k+1]);
    endfor;
    path BoiteRec;
    if Polygone:
    BoiteRec=(pointarc(fullcircle,0) for k=1 upto Petales:--pointarc(fullcircle,k*(360/Petales)) endfor --cycle) scaled 1u;
    else:
    BoiteRec=((-0.4,-0.5)--(0.4,-0.5){dir0}..{dir90}(0.5,-0.4)--(0.5,0.4){dir90}..{dir180}(0.4,0.5)--(-0.4,0.5){dir180}..{dir-90}(-0.5,0.4)--(-0.5,-0.4){dir-90}..cycle) scaled 1u;
    fi;    
    %On détermine les facteurs et produits
    for k=0 upto Petales-1:
    Facteur[k]:=ElementS[k+1];
    endfor;
    Facteur[Petales]:=Facteur[0];
    for k=0 upto Petales-1:
    Produit[k]:=Facteur[k]*Facteur[k+1];
    endfor;
    %on labelise
    if Vide=false:
    if Produits:
    else:
    for k=0 upto Petales-1:
    label(TEX("\num{"&decimal(Facteur[k])&"}"),(0.5[O,A[k]]-center BoiteRec));
    endfor;
    fi;
    if Produits or Solution:
    for k=0 upto Petales-1:
    label(TEX("\num{"&decimal(Produit[k])&"}"),(B[k]+0.5*Rayon*unitvector(B[k])));
    endfor;
    fi;
    fi;
    % On trace et on affiche...éventuellement :)
    if Aide:
    for k=0 upto Petales-1:
    drawarrow (0.5[O,A[k]]--1.75[O,B[k]]) cutbefore segment(A[k],A[k+1]) cutafter BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    drawarrow (0.5[O,A[k+1]]--1.75[O,B[k]]) cutbefore segment(A[k],A[k+1]) cutafter BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    endfor;
    fi;
    if ProduitVide:
    choix:=floor(uniformdeviate(Petales-1));
    fill (BoiteRec shifted (1.75[O,B[choix]]-center BoiteRec)) withcolor Fond;
    fill rotation(polygone(O,B0,A1,B1),O,(choix-1)*(360/Petales)) withcolor Fond;
    fill rotation(polygone(O,B0,A1,B1),O,choix*(360/Petales)) withcolor Fond;
    fi;
    if CaseVide:
    choix:=floor(uniformdeviate(Petales-1));
    for k=0 upto Petales-1:
    if k<>choix:
    fill rotation(polygone(O,B0,A1,B1),O,k*(360/Petales)) withcolor Fond;
    fi;
    endfor;
    fi;
    trace A0 for k=1 upto Petales:--A[k] endfor --cycle;
    for k=0 upto Petales-1:
    trace segment(O,B[k]) dashed withdots scaled 0.25;
    draw BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    endfor;
  \end{mplibcode}
  \else
  \begin{mpost}[mpsettings={Rayon:=\useKV[ClesRose]{Rayon};
    boolean Aide,Produits,Solution,Vide,ProduitVide,CaseVide,Polygone;
    Aide:=\useKV[ClesRose]{Aide};
    Vide:=\useKV[ClesRose]{Vide};
    Solution:=\useKV[ClesRose]{Solution};
    Produits:=\useKV[ClesRose]{Produits};
    ProduitVide:=\useKV[ClesRose]{ProduitVide};
    CaseVide:=\useKV[ClesRose]{CaseVide};
    if ProduitVide:Solution:=true fi;
    if CaseVide:Solution:=true fi;
    Polygone:=\useKV[ClesRose]{Polygone};
    Petales:=\useKV[ClesRose]{Petales};
    FacteurMin:=\useKV[ClesRose]{FacteurMin};
    FacteurMax:=\useKV[ClesRose]{FacteurMax};
    color Fond;
    Fond:=\useKV[ClesRose]{Couleur};}]
    vardef ExtraireListe(expr nbmin,nbmax,nbfacteurs)=
    numeric ElementE[],ElementS[];
    %% éléments d'entrée
    nbe=1;
    for k=nbmin upto nbmax:
    ElementE[nbe]=k;
    nbe:=nbe+1;
    endfor;
    totalE=(nbmax-nbmin)+1;
    numeric rec;
    for k=1 upto nbfacteurs:
    rec:=ceiling(uniformdeviate(totalE+1-k));
    ElementS[k]=ElementE[rec];
    numeric ElementI[];
    p:=0;
    for l=1 upto totalE+1-k:
    if l<>rec:
    p:=p+1;
    ElementI[p]=ElementE[l];
    fi;
    endfor;
    numeric ElementE[];
    for l=1 upto p:
    ElementE[l]=ElementI[l];
    endfor;
    endfor;
    enddef;
    pair A[],B[],O;
    O=(0,0);
    ExtraireListe(FacteurMin,FacteurMax,Petales);
    path cc;
    cc=cercles(O,Rayon);
    for k=0 upto Petales:
    A[k]=pointarc(cc,(360/Petales)*k);
    endfor;
    for k=0 upto Petales-1:
    B[k]=iso(A[k],A[k+1]);
    endfor;
    path BoiteRec;
    if Polygone:
    BoiteRec=(pointarc(fullcircle,0) for k=1 upto Petales:--pointarc(fullcircle,k*(360/Petales)) endfor --cycle) scaled 1u;
    else:
    BoiteRec=((-0.4,-0.5)--(0.4,-0.5){dir0}..{dir90}(0.5,-0.4)--(0.5,0.4){dir90}..{dir180}(0.4,0.5)--(-0.4,0.5){dir180}..{dir-90}(-0.5,0.4)--(-0.5,-0.4){dir-90}..cycle) scaled 1u;
    fi;    
    %On détermine les facteurs et produits
    for k=0 upto Petales-1:
    Facteur[k]=ElementS[k+1];
    endfor;
    Facteur[Petales]=Facteur[0];
    for k=0 upto Petales-1:
    Produit[k]=Facteur[k]*Facteur[k+1];
    endfor;
    %on labelise
    if Vide=false:
    if Produits:
    else:
    for k=0 upto Petales-1:
    label(LATEX("\num{"&decimal(Facteur[k])&"}"),(0.5[O,A[k]]-center BoiteRec));
    endfor;
    fi;
    if Produits or Solution:
    for k=0 upto Petales-1:
    label(LATEX("\num{"&decimal(Produit[k])&"}"),(B[k]+0.5*Rayon*unitvector(B[k])));
    endfor;
    fi;
    fi;
    % On trace et on affiche...éventuellement :)
    if Aide:
    for k=0 upto Petales-1:
    drawarrow (0.5[O,A[k]]--1.75[O,B[k]]) cutbefore segment(A[k],A[k+1]) cutafter BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    drawarrow (0.5[O,A[k+1]]--1.75[O,B[k]]) cutbefore segment(A[k],A[k+1]) cutafter BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    endfor;
    fi;
    if ProduitVide:
    choix=floor(uniformdeviate(Petales-1));
    fill (BoiteRec shifted (1.75[O,B[choix]]-center BoiteRec)) withcolor Fond;
    fill rotation(polygone(O,B0,A1,B1),O,(choix-1)*(360/Petales)) withcolor Fond;
    fill rotation(polygone(O,B0,A1,B1),O,choix*(360/Petales)) withcolor Fond;
    fi;
    if CaseVide:
    choix:=floor(uniformdeviate(Petales-1));
    for k=0 upto Petales-1:
    if k<>choix:
    fill rotation(polygone(O,B0,A1,B1),O,k*(360/Petales)) withcolor Fond;
    fi;
    endfor;
    fi;
    trace A0 for k=1 upto Petales:--A[k] endfor --cycle;
    for k=0 upto Petales-1:
    trace segment(O,B[k]) dashed withdots scaled 0.25;
    draw BoiteRec shifted (B[k]+0.5*Rayon*unitvector(B[k])) dashed evenly scaled 0.5;
    endfor;
  \end{mpost}
  \fi
}%