%!TEX pdflatex

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.text}
\usepackage{xstring}
\usepackage{fontawesome5}
\usepackage{ifthen}
\usepackage{settobox}
\usepackage{simplekv}
\usepackage{listofitems}

%=====custom texts/values/styles
\def\tkztriminotxtlogo{TriMino~TriMino~TriMino~}
\def\tkztriminoiconlogo{\scalebox{3.5}[3.5]{\textcolor{purple}{\faBahai}}}
\def\tkztriminostar{0.25}
\def\tkztriminostaralt{0.125}
\tikzset{tkztriminoside/.style={thick}}
\tikzset{tkztriminolabel/.style={font=\tkztriminofont,inner sep=1pt}}
\tikzset{tkztriminosidedeco/.style={semithick,draw=black,thin,fill=\tkztriminocolor}}

%=====lengths
\newlength{\tkztriminotmpnode}
\newlength{\tkztriminosize}
\newsavebox{\tkztriminobox}

%=====keys
\defKV[tkztrimino]{size=\setlength\tkztriminosize{#1},font=\def\tkztriminofont{#1},color=\def\tkztriminocolor{#1},bgcolor=\def\tkztriminobgcolor{#1}}
\setKVdefault[tkztrimino]{size=6.5cm,font=\normalfont,color=teal,decoration=true,txtlogo=false,iconlogo=false,bgcolor={}}

%====internal macro
\NewDocumentCommand\inttrimino{ m m m }{%
	\begin{scope}[shift={#1},rotate=#2,transform shape,line join=round]
		\IfEq{\tkztriminobgcolor}{}%
			{%
				\draw[tkztriminoside] (0,0) --++ (60:{\tkztriminosize}) --++ (-60:{\tkztriminosize}) -- cycle ;
			}%
			{%
				\draw[fill=\tkztriminobgcolor,tkztriminoside] (0,0) --++ (60:{\tkztriminosize}) --++ (-60:{\tkztriminosize}) -- cycle ;
			}%
		\ifboolKV[tkztrimino]{decoration}%
			{%
				\draw[tkztriminosidedeco] (0,0) --++ (60:{\tkztriminostar\tkztriminosize}) -- (30:{\tkztriminostaralt\tkztriminosize}) -- (0:{\tkztriminostar\tkztriminosize}) -- cycle ;
				\begin{scope}[shift={(0:{\tkztriminosize})},rotate=120]
					\fill[tkztriminosidedeco] (0,0) --++ (60:{\tkztriminostar\tkztriminosize}) -- (30:{\tkztriminostaralt\tkztriminosize}) -- (0:{\tkztriminostar\tkztriminosize}) -- cycle ;
				\end{scope}
				\begin{scope}[shift={(60:{\tkztriminosize})},rotate=-120]
					\fill[tkztriminosidedeco] (0,0) --++ (60:{\tkztriminostar\tkztriminosize}) -- (30:{\tkztriminostaralt\tkztriminosize}) -- (0:{\tkztriminostar\tkztriminosize}) -- cycle ;
				\end{scope}
			}%
			{}%
		\ifboolKV[tkztrimino]{txtlogo}%
			{%
				\path[decorate,decoration={text along path,text={|\tiny\sffamily|\tkztriminotxtlogo},text align=fit to path}] (30:{sqrt(3)/3*\tkztriminosize}) circle[radius=0.085\tkztriminosize];
			}%
			{}%
		\ifboolKV[tkztrimino]{iconlogo}%
			{%
				\draw (30:{sqrt(3)/3*\tkztriminosize}) node {\tkztriminoiconlogo};
			}%
			{}%
		\foreach \tkztext [count=\i] in {#3}{
			\ifnum\i=1
				\sbox{\tkztriminobox}{\pgfinterruptpicture \tkztriminofont\tkztext\endpgfinterruptpicture}\settoboxwidth{\tkztriminotmpnode}{\tkztriminobox}
				\ifthenelse{\lengthtest{\tkztriminotmpnode < \fpeval{1-2*\tkztriminostar}\tkztriminosize}}%
					{%
						\path (60:{\tkztriminosize}) -- (0,0) node[midway,sloped,above,tkztriminolabel,rotate=180] {\strut\tkztext} ;
					}%
					{%
						\path (60:{\tkztriminosize}) -- (0,0) node[midway,sloped,above,tkztriminolabel,rotate=180] {\strut\resizebox{\fpeval{1-2*\tkztriminostar}\tkztriminosize}{!}{\tkztext}} ;
					}%
			\fi
			\ifnum\i=2
				\sbox{\tkztriminobox}{\pgfinterruptpicture \tkztriminofont\tkztext\endpgfinterruptpicture}\settoboxwidth{\tkztriminotmpnode}{\tkztriminobox}
				\ifthenelse{\lengthtest{\tkztriminotmpnode < \fpeval{1-2*\tkztriminostar}\tkztriminosize}}%
					{%
						\path (0,0) -- ({\tkztriminosize},0) node[midway,sloped,above,tkztriminolabel] {\strut\tkztext} ;
					}%
					{%
						\path (0,0) -- ({\tkztriminosize},0) node[midway,sloped,above,tkztriminolabel] {\strut\resizebox{\fpeval{1-2*\tkztriminostar}\tkztriminosize}{!}{\tkztext}} ;
					}%
			\fi
			\ifnum\i=3
				\sbox{\tkztriminobox}{\pgfinterruptpicture \tkztriminofont\tkztext\endpgfinterruptpicture}\settoboxwidth{\tkztriminotmpnode}{\tkztriminobox}
				\ifthenelse{\lengthtest{\tkztriminotmpnode < \fpeval{1-2*\tkztriminostar}\tkztriminosize}}%
					{%
						\path ({\tkztriminosize},0) -- (60:{\tkztriminosize}) node[midway,sloped,above,tkztriminolabel,rotate=180] {\strut\tkztext} ;
					}%
					{%
						\path ({\tkztriminosize},0) -- (60:{\tkztriminosize}) node[midway,sloped,above,tkztriminolabel,rotate=180] {\strut\resizebox{\fpeval{1-2*\tkztriminostar}\tkztriminosize}{!}{\tkztext}} ; ;
					}%
			\fi
		}
	\end{scope}
}

%====main macro

\NewDocumentCommand\TriMinos{ O{} D<>{} m }{%
	\restoreKV[tkztrimino]%
	\setKV[tkztrimino]{#1}%
	\setsepchar{§}%
	\readlist*\listitemstrimino{#3}%
	\begin{tikzpicture}[#2]
		\ifnum\listitemstriminolen=19
			%avec 9 triminos (5 jokers)
			\inttrimino{(0,0)}{0}{\listitemstrimino[-1],\listitemstrimino[7],\listitemstrimino[3]}
			\inttrimino{(0:{\tkztriminosize})}{60}{\listitemstrimino[4],\listitemstrimino[6],\listitemstrimino[2]}
			\inttrimino{(0:{\tkztriminosize})}{0}{\listitemstrimino[5],\listitemstrimino[9],\listitemstrimino[-1]}
			\inttrimino{(0,0)}{-60}{\listitemstrimino[8],\listitemstrimino[12],\listitemstrimino[14]}
			\inttrimino{(0:{\tkztriminosize})}{-120}{\listitemstrimino[15],\listitemstrimino[13],\listitemstrimino[-1]}
			\inttrimino{(0:{\tkztriminosize})}{-60}{\listitemstrimino[10],\listitemstrimino[16],\listitemstrimino[18]}
			\inttrimino{(-60:{\tkztriminosize})}{-60}{\listitemstrimino[1],\listitemstrimino[-1],\listitemstrimino[-1]}
			\inttrimino{(-60:{\tkztriminosize})}{-120}{\listitemstrimino[-1],\listitemstrimino[11],\listitemstrimino[-1]}
			\inttrimino{(-30:{sqrt(3)*\tkztriminosize})}{-120}{\listitemstrimino[17],\listitemstrimino[-1],\listitemstrimino[-1]}
		\fi
		\ifnum\listitemstriminolen=25
			%avec 12 triminos (10 jokers)
			\inttrimino{(0,0)}{0}{\listitemstrimino[13],\listitemstrimino[11],\listitemstrimino[1]}
			\inttrimino{(0:{\tkztriminosize})}{60}{\listitemstrimino[2],\listitemstrimino[4],\listitemstrimino[16]}
			\inttrimino{(0:{\tkztriminosize})}{0}{\listitemstrimino[3],\listitemstrimino[5],\listitemstrimino[17]}
			\inttrimino{(0,0)}{-60}{\listitemstrimino[12],\listitemstrimino[24],\listitemstrimino[10]}
			\inttrimino{(0:{\tkztriminosize})}{-120}{\listitemstrimino[7],\listitemstrimino[9],\listitemstrimino[21]}
			\inttrimino{(0:{\tkztriminosize})}{-60}{\listitemstrimino[6],\listitemstrimino[8],\listitemstrimino[20]}
			\inttrimino{(-60:{\tkztriminosize})}{-60}{\listitemstrimino[22],\listitemstrimino[-1],\listitemstrimino[-1]}
			\inttrimino{(-60:{\tkztriminosize})}{-120}{\listitemstrimino[-1],\listitemstrimino[23],\listitemstrimino[-1]}
			\inttrimino{(-30:{sqrt(3)*\tkztriminosize})}{-120}{\listitemstrimino[19],\listitemstrimino[-1],\listitemstrimino[-1]}
			\inttrimino{(-60:{2*\tkztriminosize})}{-120}{\listitemstrimino[-1],\listitemstrimino[-1],\listitemstrimino[15]}
			\inttrimino{(-60:{2*\tkztriminosize})}{-60}{\listitemstrimino[-1],\listitemstrimino[-1],\listitemstrimino[18]}
			\inttrimino{(-60:{2*\tkztriminosize})}{-180}{\listitemstrimino[-1],\listitemstrimino[13],\listitemstrimino[-1]}
		\fi
		\ifnum\listitemstriminolen=36
		%avec 12 triminos tous remplis
			\inttrimino{(0,0)}{0}{\listitemstrimino[13],\listitemstrimino[11],\listitemstrimino[1]}
			\inttrimino{(0:{\tkztriminosize})}{60}{\listitemstrimino[2],\listitemstrimino[4],\listitemstrimino[16]}
			\inttrimino{(0:{\tkztriminosize})}{0}{\listitemstrimino[3],\listitemstrimino[5],\listitemstrimino[17]}
			\inttrimino{(0,0)}{-60}{\listitemstrimino[12],\listitemstrimino[24],\listitemstrimino[10]}
			\inttrimino{(0:{\tkztriminosize})}{-120}{\listitemstrimino[7],\listitemstrimino[9],\listitemstrimino[21]}
			\inttrimino{(0:{\tkztriminosize})}{-60}{\listitemstrimino[6],\listitemstrimino[8],\listitemstrimino[20]}
			\inttrimino{(-60:{\tkztriminosize})}{-60}{\listitemstrimino[22],\listitemstrimino[31],\listitemstrimino[25]}
			\inttrimino{(-60:{\tkztriminosize})}{-120}{\listitemstrimino[32],\listitemstrimino[23],\listitemstrimino[33]}
			\inttrimino{(-30:{sqrt(3)*\tkztriminosize})}{-120}{\listitemstrimino[19],\listitemstrimino[26],\listitemstrimino[35]}
			\inttrimino{(-60:{2*\tkztriminosize})}{-120}{\listitemstrimino[30],\listitemstrimino[28],\listitemstrimino[15]}
			\inttrimino{(-60:{2*\tkztriminosize})}{-60}{\listitemstrimino[36],\listitemstrimino[29],\listitemstrimino[18]}
			\inttrimino{(-60:{2*\tkztriminosize})}{-180}{\listitemstrimino[27],\listitemstrimino[34],\listitemstrimino[14]}
		\fi
	\end{tikzpicture}
}

\begin{document}

\TriMinos[iconlogo,bgcolor=yellow!25,font=\Large]{%
	$1+1$ § $2$ §
	$2+2$ § $4$ §
	$3+3$ § $6$ §
	{$x_{1}=\frac{-3-\sqrt{41}}{6}$ ; $x_{2}=\frac{-3+\sqrt{41}}{6}$} § $9x^{2}+9x-8$ §
	$5+5$ § $10$ §
	$6+6$ § $12$ §
	$7+7$ § $14$ §
	$8+8$ § $16$ §
	$9+9$ § $18$ §
	\faHatWizard
}

%\pagebreak
%
%\TriMinos{1a§1b§2a§2b§3a§3b§4a§4b§5a§5b§6a§6b§7a§7b§8a§8b§9a§9b§10a§10b§11a§11b§12a§12b§joker}
%
%\pagebreak
%
%\TriMinos{1a§1b§2a§2b§3a§3b§4a§4b§5a§5b§6a§6b§7a§7b§8a§8b§9a§9b§10a§10b§11a§11b§12a§12b§13a§13b§14a§14b§15a§15b§16a§16b§17a§17b§18a§18b}
%
%\pagebreak
%
%\TriMinos{1a§1b§2a§2b§3a§3b§4a§4b§5a§5b§6a§6b§7a§7b§8a§8b§9a§9b§joker}

\end{document}