summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/thematicpuzzle/thematicpuzzle.sty
blob: 763fa906eed18fad6ed61476fc7244ebc4b797be (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
% Author     : C. Pierquet
% licence    : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txtf

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{thematicpuzzle}[2024/01/09 0.1.1 Present 'puzzle' with different thematics, in TikZ]
% 0.1.1	Enhancments for colors
% 0.1.0	Initial version

%====PACKAGES
\RequirePackage{tikz}
\RequirePackage{simplekv}
\RequirePackage{xstring}
\RequirePackage{xintexpr}
\RequirePackage{listofitems}
\RequirePackage{fontawesome5}

%====ALIASES FA5 FRENCH
\newcommand\ThemProbas{\faDice}
\newcommand\ThemStats{\faChartBar}
\newcommand\ThemChimie{\faBong}
\newcommand\ThemArithm{\faListOl}
\newcommand\ThemGraphes{\faProjectDiagram}
\newcommand\ThemComplexes{\faInfo}
\newcommand\ThemMPM{\faSitemap}
\newcommand\ThemCalculs{\faIcon{square-root-alt}}
\newcommand\ThemMatrices{\faTh}
\newcommand\ThemGeometrie{\faPencilRuler}
\newcommand\ThemEspace{\faCube}
\newcommand\ThemPhysique{\faRocket}
\newcommand\ThemFonctions{\faChartArea}
\newcommand\ThemSuites{\faSignal}
\newcommand\ThemTableur{\faTable}
\newcommand\ThemAlgo{\faCode}
\newcommand\ThemEco{\faIcon{money-bill-wave}}
\newcommand\ThemPython{\faPython}
\newcommand\ThemLogique{\faYinYang}
\newcommand\VAlignTikz{current bounding box.center}

%====FRENCH VERSION
\defKV[puzzlethemes]{%
	Epaisseur=\def\puzzthmthick{#1},%
	Echelle=\def\puzzthmscale{#1},%
	CouleursFond=\def\puzzthmbg{#1},%
	CouleurBord=\def\puzzthmbc{#1},%
	Labels=\def\puzzthmlab{#1},%
	EchelleLabels=\def\puzzthmscalab{#1},%
	PoliceLabels=\def\puzzthmfontlab{#1},%
	CouleurIcones=\def\puzzthmcolicon{#1}
}
\setKVdefault[puzzlethemes]{%
	Epaisseur=1pt,%
	Echelle=1,%
	CouleursFond={},%
	CouleurBord=black,
	Labels={},%
	EchelleLabels=1.15,%
	PoliceLabels=\tiny\sffamily,%
	CouleurIcones=black
}

\NewDocumentCommand\PuzzleThemes{ O{} D<>{} m }{%
	\def\tmprounded{0.05}%
	\useKVdefault[puzzlethemes]%
	\setKV[puzzlethemes]{#1}%
	\readlist*\PuzzleListeThemes{#3}%
	\xdef\puzzthmnb{\PuzzleListeThemeslen}%
	\xdef\puzztmpalea{\fpeval{2*randint(1,2)-3}}%
	\foreach \i in {2,...,\inteval{\PuzzleListeThemeslen-1}}{%
		\xdef\puzztmpalea{\puzztmpalea,\fpeval{2*randint(1,2)-3}}%
	}%
	\readlist*\PuzzleListeAlea{\puzztmpalea}%
	\IfSubStr{\puzzthmbg}{,}%
		{%
			\StrCount{\puzzthmbg}{,}[\puzznbvirg]%
			\xintifboolexpr{\puzznbvirg < \PuzzleListeThemeslen}%
				{%
					\xdef\nbrepet{\fpeval{round(\PuzzleListeThemeslen/(\puzznbvirg+1),0,1)}}%
					\xdef\puzzlstcol{\puzzthmbg}%
					\foreach \i in {2,...,\nbrepet}{%
						\xdef\puzzlstcol{\puzzlstcol,\puzzthmbg}%
					}%
				}%
				{%
					\xdef\puzzlstcol{\puzzthmbg}%
				}%
		}%
		{%
			\xdef\puzzlstcol{\puzzthmbg}%
			\foreach \i in {2,...,\PuzzleListeThemeslen}{%
				\xdef\puzzlstcol{\puzzlstcol,\puzzthmbg}%
			}%
		}%
	\readlist*\PuzzleListeCouleurs{\puzzlstcol}%
	%environnement tikz
	\begin{tikzpicture}[scale=\puzzthmscale,transform shape,#2]%
		%styles
		\tikzset{bordure/.style={\puzzthmbc,line width={0.5*\puzzthmscale*\puzzthmthick}}}%
		\tikzset{label/.style={font=\puzzthmfontlab,text=\puzzthmcolicon}}%
		\IfEq{\puzzthmbg}{}%
			{\tikzset{fond/.style={}}}%
			{\tikzset{fond/.style={fill=\puzzthmbgcol}}}%
		%1ère pièce
		\itemtomacro\PuzzleListeCouleurs[1]{\puzzthmbgcol}%
		\itemtomacro\PuzzleListeAlea[1]{\tmprand}%
		\draw[bordure,fond] (\tmprounded,0) -- (1,0) .. controls (1+\tmprand*0.66*0.00,0.0) and (1+\tmprand*0.66*-0.04,0.4) ..
		(1+\tmprand*0.66*0.04,0.4) .. controls (1+\tmprand*0.66*0.11,0.4) and (1+\tmprand*0.66*0.26,0.2) .. 
		(1+\tmprand*0.66*0.26,0.5) .. controls (1+\tmprand*0.66*0.26,0.8) and (1+\tmprand*0.66*0.11,0.6) .. 
		(1+\tmprand*0.66*0.04,0.6) .. controls (1+\tmprand*0.66*-0.04,0.6) and (1+\tmprand*0.66*0.00,1.0) ..
		(1+\tmprand*0.66*0.00,1.0) -- (1,1) -- (\tmprounded,1) to[out=180,in=90] (0,1-\tmprounded) -- (0,\tmprounded) to[out=-90,in=180] (\tmprounded,0) ;
		%les pièces du milieu
		\foreach \i in {1,...,\inteval{\PuzzleListeThemeslen-2}}{%
			\xdef\ipu{\inteval{\i+1}}%
			\itemtomacro\PuzzleListeAlea[\i]{\tmprandg}%
			\itemtomacro\PuzzleListeAlea[\ipu]{\tmprandd}%
			\itemtomacro\PuzzleListeCouleurs[\ipu]{\puzzthmbgcol}%
			\draw[bordure,fond] (\i,0) .. controls (\i+\tmprandg*0.66*0.00,0.0) and (\i+\tmprandg*0.66*-0.04,0.4) ..
			(\i+\tmprandg*0.66*0.04,0.4) .. controls (\i+\tmprandg*0.66*0.11,0.4) and (\i+\tmprandg*0.66*0.26,0.2) .. 
			(\i+\tmprandg*0.66*0.26,0.5) .. controls (\i+\tmprandg*0.66*0.26,0.8) and (\i+\tmprandg*0.66*0.11,0.6) .. 
			(\i+\tmprandg*0.66*0.04,0.6) .. controls (\i+\tmprandg*0.66*-0.04,0.6) and (\i+\tmprandg*0.66*0.00,1.0) ..
			(\i+\tmprandg*0.66*0.00,1.0) -- (\ipu,1)
			.. controls (\ipu-\tmprandd*0.66*0.00,1.0) and (\ipu+\tmprandd*0.66*-0.04,0.6) ..
			(\ipu+\tmprandd*0.66*0.04,0.6) .. controls (\ipu+\tmprandd*0.66*0.11,0.6) and (\ipu+\tmprandd*0.66*0.26,0.8) .. 
			(\ipu+\tmprandd*0.66*0.26,0.5) .. controls (\ipu+\tmprandd*0.66*0.26,0.2) and (\ipu+\tmprandd*0.66*0.11,0.4) .. 
			(\ipu+\tmprandd*0.66*0.04,0.4) .. controls (\ipu+\tmprandd*0.66*-0.04,0.4) and (\ipu+\tmprandd*0.66*0.00,0.0) ..
			(\ipu+\tmprandd*0.66*0.00,0.0) -- (\ipu,0) -- (\i,0);
		}%
		%dernière pièce
		\itemtomacro\PuzzleListeCouleurs[\PuzzleListeThemeslen]{\puzzthmbgcol}%
		\itemtomacro\PuzzleListeAlea[-1]{\tmprand}%
		\draw[bordure,fond] (\puzzthmnb-1,0) .. controls (\puzzthmnb-1+\tmprand*0.66*0.00,0.0) and (\puzzthmnb-1+\tmprand*0.66*-0.04,0.4) ..
		(\puzzthmnb-1+\tmprand*0.66*0.04,0.4) .. controls (\puzzthmnb-1+\tmprand*0.66*0.11,0.4) and (\puzzthmnb-1+\tmprand*0.66*0.26,0.2) .. 
		(\puzzthmnb-1+\tmprand*0.66*0.26,0.5) .. controls (\puzzthmnb-1+\tmprand*0.66*0.26,0.8) and (\puzzthmnb-1+\tmprand*0.66*0.11,0.6) .. 
		(\puzzthmnb-1+\tmprand*0.66*0.04,0.6) .. controls (\puzzthmnb-1+\tmprand*0.66*-0.04,0.6) and (\puzzthmnb-1+\tmprand*0.66*0.00,1.0) ..
		(\puzzthmnb-1+\tmprand*0.66*0.00,1.0) -- (\puzzthmnb-1,1) -- (\puzzthmnb-\tmprounded,1) to[out=0,in=90] (\puzzthmnb,1-\tmprounded) -- (\puzzthmnb,\tmprounded) to[out=-90,in=0] (\puzzthmnb-\tmprounded,0) -- (\puzzthmnb-1,0) ;
		%icones
		\foreach \i in {1,...,\PuzzleListeThemeslen}{%
			\draw ({\i-0.5},0.5) node[scale=1.25,text=\puzzthmcolicon] {\PuzzleListeThemes[\i]} ;
		}%
		%labels dessous
		\IfEq{\puzzthmlab}{}%
			{}%
			{%
				\readlist*\PuzzleListeLabels{\puzzthmlab}%
				\foreach \i in {1,...,\PuzzleListeLabelslen}{%
					\draw ({\i-0.5},0) node[below,inner sep=1pt,scale=\puzzthmscalab,label] {\PuzzleListeLabels[\i]} ;
				}%
			}%
	\end{tikzpicture}%
}

%====ENGLISH VERSION
\defKV[themepuzzle]{%
	Thickness=\def\puzzthmthick{#1},%
	Scale=\def\puzzthmscale{#1},%
	BgColors=\def\puzzthmbg{#1},%
	BorderColor=\def\puzzthmbc{#1},%
	Labels=\def\puzzthmlab{#1},%
	ScaleLabels=\def\puzzthmscalab{#1},%
	FontLabels=\def\puzzthmfontlab{#1},%
	IconsColor=\def\puzzthmcolicon{#1}
}
\setKVdefault[themepuzzle]{%
	Thickness=1pt,%
	Scale=1,%
	BgColors={},%
	BorderColor=black,
	Labels={},%
	ScaleLabels=1.15,%
	FontLabels=\tiny\sffamily,%
	IconsColor=black
}

\NewDocumentCommand\ThematicPuzzle{ O{} D<>{} m }{%
	\def\tmprounded{0.05}%
	\useKVdefault[themepuzzle]%
	\setKV[themepuzzle]{#1}%
	\readlist*\PuzzleListeThemes{#3}%
	\xdef\puzzthmnb{\PuzzleListeThemeslen}%
	\xdef\puzztmpalea{\fpeval{2*randint(1,2)-3}}%
	\foreach \i in {2,...,\inteval{\PuzzleListeThemeslen-1}}{%
		\xdef\puzztmpalea{\puzztmpalea,\fpeval{2*randint(1,2)-3}}%
	}%
	\readlist*\PuzzleListeAlea{\puzztmpalea}%
	\IfSubStr{\puzzthmbg}{,}%
		{%
			\StrCount{\puzzthmbg}{,}[\puzznbvirg]%
			\xintifboolexpr{\puzznbvirg < \PuzzleListeThemeslen}%
				{%
					\xdef\nbrepet{\fpeval{round(\PuzzleListeThemeslen/(\puzznbvirg+1),0,1)}}%
					\xdef\puzzlstcol{\puzzthmbg}%
					\foreach \i in {2,...,\nbrepet}{%
						\xdef\puzzlstcol{\puzzlstcol,\puzzthmbg}%
					}%
				}%
				{%
					\xdef\puzzlstcol{\puzzthmbg}%
				}%
		}%
		{%
			\xdef\puzzlstcol{\puzzthmbg}%
			\foreach \i in {2,...,\PuzzleListeThemeslen}{%
				\xdef\puzzlstcol{\puzzlstcol,\puzzthmbg}%
			}%
		}%
	\readlist*\PuzzleListeCouleurs{\puzzlstcol}%
	%environnement tikz
	\begin{tikzpicture}[scale=\puzzthmscale,transform shape,#2]%
		%styles
		\tikzset{border/.style={\puzzthmbc,line width={0.5*\puzzthmscale*\puzzthmthick}}}%
		\tikzset{label/.style={font=\puzzthmfontlab,text=\puzzthmcolicon}}%
		\IfEq{\puzzthmbg}{}%
			{\tikzset{background/.style={}}}%
			{\tikzset{background/.style={fill=\puzzthmbgcol}}}%
		%1ère pièce
		\itemtomacro\PuzzleListeCouleurs[1]{\puzzthmbgcol}%
		\itemtomacro\PuzzleListeAlea[1]{\tmprand}%
		\draw[border,background] (\tmprounded,0) -- (1,0) .. controls (1+\tmprand*0.66*0.00,0.0) and (1+\tmprand*0.66*-0.04,0.4) ..
		(1+\tmprand*0.66*0.04,0.4) .. controls (1+\tmprand*0.66*0.11,0.4) and (1+\tmprand*0.66*0.26,0.2) .. 
		(1+\tmprand*0.66*0.26,0.5) .. controls (1+\tmprand*0.66*0.26,0.8) and (1+\tmprand*0.66*0.11,0.6) .. 
		(1+\tmprand*0.66*0.04,0.6) .. controls (1+\tmprand*0.66*-0.04,0.6) and (1+\tmprand*0.66*0.00,1.0) ..
		(1+\tmprand*0.66*0.00,1.0) -- (1,1) -- (\tmprounded,1) to[out=180,in=90] (0,1-\tmprounded) -- (0,\tmprounded) to[out=-90,in=180] (\tmprounded,0) ;
		%les pièces du milieu
		\foreach \i in {1,...,\inteval{\PuzzleListeThemeslen-2}}{%
			\xdef\ipu{\inteval{\i+1}}%
			\itemtomacro\PuzzleListeAlea[\i]{\tmprandg}%
			\itemtomacro\PuzzleListeAlea[\ipu]{\tmprandd}%
			\itemtomacro\PuzzleListeCouleurs[\ipu]{\puzzthmbgcol}%
			\draw[border,background] (\i,0) .. controls (\i+\tmprandg*0.66*0.00,0.0) and (\i+\tmprandg*0.66*-0.04,0.4) ..
			(\i+\tmprandg*0.66*0.04,0.4) .. controls (\i+\tmprandg*0.66*0.11,0.4) and (\i+\tmprandg*0.66*0.26,0.2) .. 
			(\i+\tmprandg*0.66*0.26,0.5) .. controls (\i+\tmprandg*0.66*0.26,0.8) and (\i+\tmprandg*0.66*0.11,0.6) .. 
			(\i+\tmprandg*0.66*0.04,0.6) .. controls (\i+\tmprandg*0.66*-0.04,0.6) and (\i+\tmprandg*0.66*0.00,1.0) ..
			(\i+\tmprandg*0.66*0.00,1.0) -- (\ipu,1)
			.. controls (\ipu-\tmprandd*0.66*0.00,1.0) and (\ipu+\tmprandd*0.66*-0.04,0.6) ..
			(\ipu+\tmprandd*0.66*0.04,0.6) .. controls (\ipu+\tmprandd*0.66*0.11,0.6) and (\ipu+\tmprandd*0.66*0.26,0.8) .. 
			(\ipu+\tmprandd*0.66*0.26,0.5) .. controls (\ipu+\tmprandd*0.66*0.26,0.2) and (\ipu+\tmprandd*0.66*0.11,0.4) .. 
			(\ipu+\tmprandd*0.66*0.04,0.4) .. controls (\ipu+\tmprandd*0.66*-0.04,0.4) and (\ipu+\tmprandd*0.66*0.00,0.0) ..
			(\ipu+\tmprandd*0.66*0.00,0.0) -- (\ipu,0) -- (\i,0);
		}%
		%dernière pièce
		\itemtomacro\PuzzleListeCouleurs[\PuzzleListeThemeslen]{\puzzthmbgcol}%
		\itemtomacro\PuzzleListeAlea[-1]{\tmprand}%
		\draw[border,background] (\puzzthmnb-1,0) .. controls (\puzzthmnb-1+\tmprand*0.66*0.00,0.0) and (\puzzthmnb-1+\tmprand*0.66*-0.04,0.4) ..
		(\puzzthmnb-1+\tmprand*0.66*0.04,0.4) .. controls (\puzzthmnb-1+\tmprand*0.66*0.11,0.4) and (\puzzthmnb-1+\tmprand*0.66*0.26,0.2) .. 
		(\puzzthmnb-1+\tmprand*0.66*0.26,0.5) .. controls (\puzzthmnb-1+\tmprand*0.66*0.26,0.8) and (\puzzthmnb-1+\tmprand*0.66*0.11,0.6) .. 
		(\puzzthmnb-1+\tmprand*0.66*0.04,0.6) .. controls (\puzzthmnb-1+\tmprand*0.66*-0.04,0.6) and (\puzzthmnb-1+\tmprand*0.66*0.00,1.0) ..
		(\puzzthmnb-1+\tmprand*0.66*0.00,1.0) -- (\puzzthmnb-1,1) -- (\puzzthmnb-\tmprounded,1) to[out=0,in=90] (\puzzthmnb,1-\tmprounded) -- (\puzzthmnb,\tmprounded) to[out=-90,in=0] (\puzzthmnb-\tmprounded,0) -- (\puzzthmnb-1,0) ;
		%icones
		\foreach \i in {1,...,\PuzzleListeThemeslen}{%
			\draw ({\i-0.5},0.5) node[scale=1.25,text=\puzzthmcolicon] {\PuzzleListeThemes[\i]} ;
		}%
		%labels dessous
		\IfEq{\puzzthmlab}{}%
			{}%
			{%
				\readlist*\PuzzleListeLabels{\puzzthmlab}%
				\foreach \i in {1,...,\PuzzleListeLabelslen}{%
					\draw ({\i-0.5},0) node[below,inner sep=1pt,scale=\puzzthmscalab,label] {\PuzzleListeLabels[\i]} ;
				}%
			}%
	\end{tikzpicture}%
}


\endinput