summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCPapiers.tex
blob: 3929600a6e69ab0855cad36e08d9e8d6ee238059 (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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
%%%
% Papiers
%%%
\def\filedatePapiers{2024/08/04}%
\def\fileversionPapiers{0.1}%
\message{-- \filedatePapiers\space v\fileversionPapiers}%
%
\setKVdefault[Papiers]{Cinq=true,Seyes=false,Echelle=8,Isometrique=false,IsometriquePointe=false,Millimetre=false,Triangle=false,Largeur=5,Hauteur=4,Couleur=black,Grille=-1,GrillePointe=-1,PageEntiere=false,ZoneTexte=false,Baseline=false,CodeAfter=false}%
\defKV[Papiers]{Traces=\setKV[Papiers]{CodeAfter}}

%\def\MPBaseLineSkip#1#2#3{%à retravailler : ne fonctionne pas :(
%  %
%  \ifluatex
%  \mplibforcehmode
%  \begin{mplibcode}
%    path horizon,verticon;
%    horizon=(0,0)--(#1*cm,0);
%    %verticon=(0,0)--(0,#2*cm);
%    drawoptions(withcolor #3);
%    %for k=0 step 0.5 until #1:
%    %draw verticon shifted((k*cm,0));
%    %endfor;
%    for k=(#2-(\mpdim{1.6ex}/1cm)) step (-\mpdim{\baselineskip}/1cm) until 0:
%    draw horizon shifted((0,k*cm));
%    endfor;
%    drawoptions(withcolor blue);
%    for k=#2 step (-\mpdim{\baselineskip}/1cm) until 0:
%    draw horizon shifted((0,k*cm));
%    endfor;
%  \end{mplibcode}
%  \fi
%}

\def\MPGrilleCode{%
  PapierLargeur=\PapierLargeur;
  PapierHauteur=\PapierHauteur;
  PapierGrille=\PapierGrille;
  PapierGrillePointe=\PapierGrillePointe;
  color PapierCouleur;
  PapierCouleur=\useKV[Papiers]{Couleur};
  %
  path horizon,verticon;
  horizon=(0,0)--(PapierLargeur*cm,0);
  verticon=(0,0)--(0,PapierHauteur*cm);
  vardef Papier=
  picture Papiers;
  Papiers=image(
  drawoptions(withcolor PapierCouleur);
  if PapierGrillePointe>0:
  for k=0 step (PapierGrillePointe*100) until (PapierLargeur*100):
  for l=0 step (PapierGrillePointe*100) until (PapierHauteur*100):
  fill (cercles((0,0),1pt) shifted(((k/100)*cm,(l/100)*cm)));
  endfor;
  endfor;
  else:
  for k=0 step (PapierGrille*100) until (PapierLargeur*100):
  draw verticon shifted(((k/100)*cm,0));
  endfor;
  for k=0 step (PapierGrille*100) until (PapierHauteur*100):
  draw horizon shifted((0,(k/100)*cm));
  endfor;
  fi;
  );
  Papiers
  enddef;
}%

\def\MPGrille{%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}%
    \MPGrilleCode
    trace Papier;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={\MPGrilleCode}]
    trace Papier;
  \end{mpost}%
  \fi%
}%

\def\MPCinq{%
  \xdef\PapierGrille{0.5}%
  \MPGrille
}%

\def\MPSeyesCode{%
  PapierLargeur=\PapierLargeur;
  PapierHauteur=\PapierHauteur;
  color PapierCouleur;
  PapierCouleur=\useKV[Papiers]{Couleur};
  u:=\useKV[Papiers]{Echelle};
  path horizon,verticon;
  horizon=(0,0)--(PapierLargeur*cm,0);
  verticon=(0,0)--(0,PapierHauteur*cm);
  vardef Seyes=
  picture PapierSeyes;
  PapierSeyes=image(
  drawoptions(withcolor PapierCouleur);
  for k=0 step u until (PapierLargeur*10):
  draw verticon shifted(((k/10)*cm,0));
  endfor;
  for k=0 step (u/4) until (PapierHauteur*10):
  draw horizon shifted((0,(k/10)*cm)) withpen pencircle scaled 0.5;
  endfor;
  for k=0 step u until (PapierHauteur*10):
  draw horizon shifted((0,(k/10)*cm)) withpen pencircle scaled 1.25;
  endfor;
  );
  PapierSeyes
  enddef;
}

\def\MPSeyes{%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}%
    \MPSeyesCode
    trace Seyes;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={\MPSeyesCode}]%
    trace Seyes;
  \end{mpost}
  \fi%
}%

\def\MPMillimetreCode{%
  PapierLargeur=\PapierLargeur;
  PapierHauteur=\PapierHauteur;
  color PapierCouleur;
  PapierCouleur=\useKV[Papiers]{Couleur};
  path horizon,verticon;
  horizon=(0,0)--(PapierLargeur*cm,0);
  verticon=(0,0)--(0,PapierHauteur*cm);
  vardef MPMilli=
  picture MPMillimetre;
  MPMillimetre=image(
  drawoptions(withcolor PapierCouleur);
  for k=0 step 1 until (PapierLargeur*10):
  draw verticon shifted(((k/10)*cm,0)) withpen pencircle scaled 0.2;
  endfor;
  for k=0 step 5 until (PapierLargeur*10):
  draw verticon shifted(((k/10)*cm,0)) withpen pencircle scaled 0.5;
  endfor;
  for k=0 step 1 until (PapierLargeur):
  draw verticon shifted((k*cm,0)) withpen pencircle scaled 1.25;
  endfor;
  for k=0 step 1 until (PapierHauteur*10):
  draw horizon shifted((0,(k/10)*cm)) withpen pencircle scaled 0.2;
  endfor;
  for k=0 step 5 until (PapierHauteur*10):
  draw horizon shifted((0,(k/10)*cm)) withpen pencircle scaled 0.5;
  endfor;
  for k=0 step 1 until (PapierHauteur):
  draw horizon shifted((0,k*cm)) withpen pencircle scaled 1.25;
  endfor;
  );
  MPMillimetre
  enddef;
}

\def\MPMillimetre{%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}%
    \MPMillimetreCode
    trace MPMilli;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={\MPMillimetreCode}]
    trace MPMilli;
  \end{mpost}%
  \fi%
}%

\def\MPIsometriqueCode{%
  PapierLargeur=\PapierLargeur;
  PapierHauteur=\PapierHauteur;
  color PapierCouleur;
  PapierCouleur=\useKV[Papiers]{Couleur};
  path diagon,antidiagon;
  diagon=(0,0)--PapierHauteur*cm*(sqrt(3),1);
  antidiagon=(0,0)--PapierHauteur*cm*(-sqrt(3),1);
  vardef MPIso=
  picture MPIsom;
  MPIsom=image(
  drawoptions(withcolor PapierCouleur);
  for k=0 upto 2*(PapierLargeur+PapierHauteur):
  draw antidiagon shifted((k*cm,0));
  endfor;
  for k=-(2*ceiling(PapierLargeur+PapierHauteur)) upto (2*ceiling(PapierLargeur+PapierHauteur)):
  draw diagon shifted((k*cm,0));
  endfor;
  clip currentpicture to polygone((0,0),(PapierLargeur*cm,0),(PapierLargeur*cm,PapierHauteur*cm),(0,PapierHauteur*cm));
  );
  MPIsom
  enddef;
}

\def\MPIsometrique{%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}%
    \MPIsometriqueCode
    trace MPIso;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={\MPIsometriqueCode}]
    trace MPIso;
  \end{mpost}%
  \fi%
}%

\def\MPIsometriquePointeCode{%
  PapierLargeur=\PapierLargeur;
  PapierHauteur=\PapierHauteur;
  color PapierCouleur;
  PapierCouleur=\useKV[Papiers]{Couleur};
  pair diagon,antidiagon;
  diagon=(1pt,1pt);
  antidiagon=(1pt+0.5cm,1pt+0.5*(sqrt(3)*1cm/3));
  vardef TraceIsoPointe=
  picture PapierIsoPointe;
  PapierIsoPointe=image(
  drawoptions(withcolor PapierCouleur);
  for k=0 step (sqrt(3)/3) until (PapierHauteur):
  for l=0 step 1 until (PapierLargeur):
  fill (cercles(diagon,1pt) shifted((l*cm,k*cm)));
  fill (cercles(antidiagon,1pt) shifted((l*cm,k*cm)));
  endfor;
  endfor;
  clip currentpicture to polygone((0,0),(PapierLargeur*cm+2pt,0),(PapierLargeur*cm+2pt,PapierHauteur*cm+1pt),(0,PapierHauteur*cm+1pt));
  );
  PapierIsoPointe
  enddef;
}
    
\def\MPIsometriquePointe{%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}%
    \MPIsometriquePointeCode
    trace TraceIsoPointe;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={\MPIsometriquePointeCode}]
    trace TraceIsoPointe;
  \end{mpost}%
  \fi%
}%

\def\MPTriangulaireCode{%
  PapierLargeur=\PapierLargeur;
  PapierHauteur=\PapierHauteur;
  color PapierCouleur;
  PapierCouleur=\useKV[Papiers]{Couleur};
  path horizon,diagon,antidiagon;
  horizon=(0,0)--(PapierLargeur*cm,0);
  diagon=(0,0)--PapierHauteur*cm*(sqrt(3)/3,1);
  antidiagon=(0,0)--PapierHauteur*cm*(-sqrt(3)/3,1);
  vardef PapierTri=
  picture PapierTriangle;
  PapierTriangle=image(
  drawoptions(withcolor PapierCouleur);
  for k=0 upto 2*ceiling(PapierLargeur):
  draw diagon shifted((k*cm,0));
  draw antidiagon shifted((k*cm,0));
  endfor;
  for k=sqrt(3) step (sqrt(3)) until (PapierHauteur):
  draw diagon shifted((0,k*cm));
  endfor;
  for k=0 step (sqrt(3)/2) until (PapierHauteur):
  draw horizon shifted((0,k*cm));
  endfor;
  clip currentpicture to polygone((0,0),(PapierLargeur*cm,0),(PapierLargeur*cm,PapierHauteur*cm),(0,PapierHauteur*cm));
  );
  PapierTriangle
  enddef;
}

\def\MPTriangulaire{%
  \ifluatex%
  \mplibforcehmode%
  \begin{mplibcode}%
    \MPTriangulaireCode
    trace PapierTri;
  \end{mplibcode}%
  \else%
  \begin{mpost}[mpsettings={\MPTriangulaireCode}]
    trace PapierTri;
  \end{mpost}%
  \fi%
}%

\RequirePackage{ifoddpage}

\newlength{\PapierLeftCurrent}

\def\PfCPapierTest{%
  \xintifboolexpr{\useKV[Papiers]{GrillePointe}>0 || \useKV[Papiers]{Grille}>0}{%
    \MPGrille%
  }{\ifboolKV[Papiers]{Baseline}{%
      \MPBaseLineSkip{\PapierLargeur}{\PapierHauteur}{\PapierCouleur}%
    }{%
      \ifboolKV[Papiers]{IsometriquePointe}{%
        \MPIsometriquePointe%
      }{%
        \ifboolKV[Papiers]{Triangle}{%
          \MPTriangulaire%
        }{\ifboolKV[Papiers]{Millimetre}{%
            \MPMillimetre%
          }{\ifboolKV[Papiers]{Isometrique}{%
              \MPIsometrique%
            }{\ifboolKV[Papiers]{Seyes}{%
                \MPSeyes%
              }{\MPCinq%
              }%
            }%
          }%
        }%
      }%
    }%
  }%
}%

\newcommand\Papiers[1][]{%
  \useKVdefault[Papiers]%
  \setKV[Papiers]{#1}%
  \xdef\PapierLargeur{\useKV[Papiers]{Largeur}}%
  \xdef\PapierHauteur{\useKV[Papiers]{Hauteur}}%
  \xdef\PapierCouleur{\useKV[Papiers]{Couleur}}%
  \xdef\PapierGrille{\useKV[Papiers]{Grille}}%
  \xdef\PapierGrillePointe{\useKV[Papiers]{GrillePointe}}%
  \ifboolKV[Papiers]{ZoneTexte}{%
    \checkoddpage\ifoddpage%
    \setlength{\PapierLeftCurrent}{\oddsidemargin}%
    \else%
    \setlength{\PapierLeftCurrent}{\evensidemargin}%
    \fi%
    \xdef\PapierLeft{\the\dimexpr1in+\PapierLeftCurrent}%
    \xdef\PapierBottom{\fpeval{\paperheight-\textheight-\voffset-\headheight-\topmargin-\headsep-1in}}%
    \xdef\PapierHauteur{\fpeval{\textheight/1cm}}%
    \xdef\PapierLargeur{\fpeval{\textwidth/1cm}}%
    \begin{tikzpicture}[remember picture,overlay]%
      \node[anchor=south west,inner sep=0pt,transform canvas={xshift=\PapierLeft,yshift=\PapierBottom}] at (current page.south west) {%
        \PfCPapierTest%
      };%
    \end{tikzpicture}%
  }{%
    \ifboolKV[Papiers]{PageEntiere}{%
      \checkoddpage\ifoddpage%
      \setlength{\PapierLeftCurrent}{\oddsidemargin}%
      \else%
      \setlength{\PapierLeftCurrent}{\evensidemargin}%
      \fi%
      \xdef\PapierLeft{\the\dimexpr1in+\PapierLeftCurrent}%
      \xdef\PapierBottom{\fpeval{\paperheight-\textheight-\voffset-\headheight-\topmargin-\headsep-1in}}%
      \xdef\PapierHauteur{\fpeval{\paperheight/1cm}}%
      \xdef\PapierLargeur{\fpeval{\paperwidth/1cm}}%
      \begin{tikzpicture}[remember picture,overlay]%
        \node[anchor=south west,inner sep=0pt] at (current page.south west) {%
          \PfCPapierTest%
        };%
      \end{tikzpicture}%
    }{%
      \PfCPapierTest
    }%
  }%
}%