%!TEX pdflatex

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usepackage{simplekv}
\usepackage{xstring}
\usepackage{ifthen}
\usepackage{openmoji}
\usepackage{calc}
\usetikzlibrary{bbox,decorations,decorations.pathmorphing}

%https://tex.stackexchange.com/questions/719042/tikz-how-clip-to-complement-of-a-region
\usetikzlibrary{spath3}
\tikzset{
	invclip/.style={clip even odd rule,overlay,insert path={[reset cm](-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)},},
	clip even odd rule/.code={\pgfseteorule}
}
\makeatletter
\tikzset{use path now/.code={\pgfsyssoftpath@setcurrentpath#1}}
\makeatother

\newlength\tkzlegoheight
\newlength\tkzlegoheightlogo
\newlength\tkzlegowidthlogo

\defKV[tkzshapelego]{%
	color skin=\def\tkzshapelegoskincolor{#1},%
	color sweat=\def\tkzshapelegosweatcolor{#1},%
	color pant=\def\tkzshapelegopantcolor{#1},%
	color belt=\tikzset{lego shape belt/.style={fill=#1}},
	color bottom belt=\tikzset{lego shape bottom belt/.style={fill=#1}},
	color body=\tikzset{lego shape body/.style={fill=#1}},
	color arm=\tikzset{lego shape arm/.style={fill=#1}},
	color arm shadow=\tikzset{lego shape arm shadow/.style={fill=#1}},
	color hand=\tikzset{lego shape hand/.style={fill=#1}},
	color hand shadow=\tikzset{lego shape hand shadow/.style={fill=#1}},
	color neck=\tikzset{lego shape neck/.style={fill=#1}},
	color head=\tikzset{lego shape head/.style={fill=#1}},
	color hair=\tikzset{lego shape hair/.style={fill=#1}},
	color top pant=\tikzset{lego shape top pant/.style={fill=#1}},
	color middle pant=\tikzset{lego shape middle pant/.style={fill=#1}},
	color foot=\tikzset{lego shape foot/.style={fill=#1}},%
	logo=\def\tkzshapelegologo{#1},%
	scale logo=\def\tkzshapelegoscalelogo{#1}
}
\setKVdefault[tkzshapelego]{%
	color skin={},
	color sweat={},%
	color pant={},
	color belt=darkgray,
	color bottom belt=blue!75,
	color body=red,
	color arm=red,
	color arm shadow=red!85!black,
	color hand=yellow,
	color hand yellow!85!black,
	color neck=yellow,
	color head=yellow,
	color hair=yellow,
	color top pant=blue!75,
	color middle pant=blue!75,
	color foot=darkgray!50!black,%
	display logo=false,%
	custom logo=false,%
	logo={ },%
	scale logo=0.667,
	man=false,%
	woman=true,%
	empty=false,%
	hairstyle=0,
	seed=365479
}

\tikzset{lego shape belt/.style={fill=gray}}
\tikzset{lego shape bottom belt/.style={fill=blue!75!black}}
\tikzset{lego shape body/.style={fill=red}}
\tikzset{lego shape arm/.style={fill=red}}
\tikzset{lego shape arm shadow/.style={fill=red!85!black}}
\tikzset{lego shape hand/.style={fill=yellow}}
\tikzset{lego shape hand shadow/.style={fill=yellow!85!black}}
\tikzset{lego shape neck/.style={fill=yellow}}
\tikzset{lego shape head/.style={fill=yellow}}
\tikzset{lego shape hair/.style={fill=yellow}}
\tikzset{lego shape top pant/.style={fill=blue!75!black}}
\tikzset{lego shape middle pant/.style={fill=blue!75!black}}
\tikzset{lego shape foot/.style={fill=white}}

\newcommand\inttkzshapelegoeyebrowwoman[3][1]{%
	\begin{scope}[shift={(#2)},xscale=#1]
		\filldraw[black,line width=\fpeval{\tkzlegoscale*0.3}mm] (-0.3,-0.2) to[bend left=45] (0.6,-0.05) to[bend right=25] cycle ;
	\end{scope}
	\begin{scope}[shift={(#3)},xscale=#1]
		\draw[line width=\fpeval{\tkzlegoscale*0.8}mm] plot[smooth] coordinates{(-0.3,0.25) (0,0.35) (0.25,0.35) (0.6,0.45)} ;
		\foreach \i in {0,2,4}{%
			\draw[line width=\fpeval{\tkzlegoscale*0.6}mm] ({0.25+\i*(0.35)/4},{0.35+\i*(0.1)/4}) --++ (70:0.15) ;
		}%
	\end{scope}
}

\newcommand\inttkzshapelegoeyebrowman[2][1]{%
	\begin{scope}[shift={(#2)},xscale=#1]
		\filldraw[black] (-0.3,-0.15) to[bend left=50] (0.5,-0.15) to[bend right=10] cycle ;
	\end{scope}
}

\newcommand\inttkzshapelegohairstylemanA[1]{%
	\begin{scope}[shift={(#1)}]
		\pgfmathsetseed{\useKV[tkzshapelego]{seed}}%
		%\draw[lego shape hair,decoration={random steps,segment length=\fpeval{\tkzlegoscale*6}mm,amplitude=\fpeval{\tkzlegoscale*2}mm}] (-2.15,-1) decorate {-- (2.15,-1)} to[bend right=85,looseness=1.45] cycle ;
		\draw[lego shape hair,decoration={random steps,segment length=\fpeval{\tkzlegoscale*6}mm,amplitude=\fpeval{\tkzlegoscale*1.5}mm}] (-2.15,-1) -- (-2.15,-2) -- (-1.8,-1) decorate {-- (1.8,-1)} -- (2.15,-2) -- (2.15,-1) to[bend right=85,looseness=1.3] cycle ;
	\end{scope}
}

\newcommand\inttkzshapelegohairstylewomanA[1]{%
	\begin{scope}[shift={(#1)}]
		\pgfmathsetseed{\useKV[tkzshapelego]{seed}}%
		\draw[lego shape hair,decoration={random steps,segment length=\fpeval{\tkzlegoscale*6}mm,amplitude=\fpeval{\tkzlegoscale*1.5}mm}] (-2.15,-1) to[out=-90,in=10,looseness=0.5] (-2.5,-2.75) to[out=0,in=-95] (-1.7,-1) decorate { -- (1.7,-1)} to[out=-85,in=180] (2.5,-2.75) to[out=170,in=-90,looseness=0.5] (2.15,-1) to[bend right=85,looseness=1.3] cycle ;
	\end{scope}
}

\NewDocumentCommand\pictobrickfigurine{O{}D<>{}m}{%
	\restoreKV[tkzshapelego]%
	\setKV[tkzshapelego]{#1}%
	%----colors shortcuts if necessary
	\IfStrEq{\tkzshapelegoskincolor}{}%
	{}
	{%
		\tikzset{lego shape hand/.style={fill=\tkzshapelegoskincolor}}%
		\tikzset{lego shape hand shadow/.style={fill=\tkzshapelegoskincolor!85!black}}%
		\tikzset{lego shape neck/.style={fill=\tkzshapelegoskincolor}}%
		\tikzset{lego shape head/.style={fill=\tkzshapelegoskincolor}}%
	}%
	{}%
	\IfStrEq{\tkzshapelegosweatcolor}{}%
	{}
	{%
		\tikzset{lego shape body/.style={fill=\tkzshapelegosweatcolor}}%
		\tikzset{lego shape arm/.style={fill=\tkzshapelegosweatcolor}}%
		\tikzset{lego shape arm shadow/.style={fill=\tkzshapelegosweatcolor!85!black}}%
	}%
	{}%
	\IfStrEq{\tkzshapelegopantcolor}{}%
	{}
	{%
		\tikzset{lego shape belt/.style={fill=\tkzshapelegopantcolor}}%
		\tikzset{lego shape bottom belt/.style={fill=\tkzshapelegopantcolor}}%
		\tikzset{lego shape top pant/.style={fill=\tkzshapelegopantcolor}}%
		\tikzset{lego shape middle pant/.style={fill=\tkzshapelegopantcolor}}%
	}%
	{}%
	\ifboolKV[tkzshapelego]{empty}%
	{%
		\tikzset{lego shape belt/.style={}}%
		\tikzset{lego shape bottom belt/.style={}}%
		\tikzset{lego shape body/.style={}}%
		\tikzset{lego shape arm/.style={}}%
		\tikzset{lego shape arm shadow/.style={}}%
		\tikzset{lego shape hand/.style={}}%
		\tikzset{lego shape hand shadow/.style={}}%
		\tikzset{lego shape neck/.style={}}%
		\tikzset{lego shape head/.style={}}%
		\tikzset{lego shape hair/.style={}}%
		\tikzset{lego shape top pant/.style={}}%
		\tikzset{lego shape middle pant/.style={}}%
		\tikzset{lego shape foot/.style={}}%
	}%
	{}%
	\ifboolKV[tkzshapelego]{man}{\setKV[tkzshapelego]{woman=false}}{}%if man = true => woman = false
	%----lengths
	\setlength\tkzlegoheight{#3}%
	\xdef\tkzlegoscale{\fpeval{\tkzlegoheight/16cm}}%
	\setlength\tkzlegoheightlogo{\fpeval{\tkzshapelegoscalelogo*4/16}\tkzlegoheight}%
	\setlength\tkzlegowidthlogo{\fpeval{\tkzshapelegoscalelogo*4/16}\tkzlegoheight}%
	%----picture
	\begin{tikzpicture}[bezier bounding box,scale=\tkzlegoscale,line width=\fpeval{\tkzlegoscale*0.8}mm,line join=round,line cap=round,#2,transform shape]
		%body
		\draw[lego shape body] (-3,0) -- (3,0) -- (3,0.6) {[rounded corners=\fpeval{\tkzlegoscale*4}mm] -- (2.25,5) -- (-2.25,5)} -- (-3,0.6) -- (-3,0) -- cycle ;
		%neck
		\draw[lego shape neck] (-1.35,5) rectangle (1.35,5.45) ;
		%head
		\draw[lego shape head,rounded corners=\fpeval{\tkzlegoscale*8}mm] (-2,5.45) rectangle (2,{5.45+3.385}) ;
		%hair
		\ifnum\useKV[tkzshapelego]{hairstyle}=0\relax%
		\draw[lego shape hair] (-1,{5.45+3.385}) {[rounded corners=\fpeval{\tkzlegoscale*2}mm] --++ (0,0.7) --++ (2,0)} --++ (0,-0.7) -- cycle ;
		\fi%
		%belt
		\draw[lego shape belt] (-2.75,0) rectangle (2.75,-0.8) ;
		\draw[lego shape bottom belt] (-0.25,-0.8) -- (-0.25,-3.1) -- (-0.1,-3.3) -- (0.1,-3.3) -- (0.25,-3.1) -- (0.25,-0.8) -- cycle ;
		%leg 1
		\draw[lego shape middle pant] (-2.75,-3) --++ (0,-3.3) --++ (2.65,0) --++ (0,3) -- (-0.25,-3.1) --++ (0,0.15) |- (-2.75,-0.8) -- cycle ;
		\draw[lego shape top pant] (-2.75,-0.8) rectangle (-0.25,-3) ;
		\draw[lego shape foot] (-2.75,-5.1) rectangle (-0.1,-6.3) ;
		%leg 2
		\begin{scope}[xscale=-1]
			\draw[lego shape middle pant] (-2.75,-3) --++ (0,-3.3) --++ (2.65,0) --++ (0,3) -- (-0.25,-3.1) --++ (0,0.15) |- (-2.75,-0.8) -- cycle ;
			\draw[lego shape top pant] (-2.75,-0.8) rectangle (-0.25,-3) ;
			\draw[lego shape foot] (-2.75,-5.1) rectangle (-0.1,-6.3) ;
		\end{scope}
		%arm 1
		\draw[lego shape arm] (2.3175,4.6) {[rounded corners=\fpeval{\tkzlegoscale*6}mm] -- (3,4.6) -- (4.2,2.6)} -- (4.6,0.75) to[bend right=30] (3,0.5) -- cycle ;
		\begin{scope}
			\path[save path=\pathlegotikzarm] (3.34,0.5375) --++(-80:0.5) to[bend right=60] ++ (-80:1.8) --++ (100:0.5) to[bend left=110,looseness=3] ++ (10:1) --++ (-80:0.5) to[bend right=60] ++ (100:1.8) --++ (100:0.45) to[bend right=20] (3.34,0.5375) ;
			\clip[use path now=\pathlegotikzarm,invclip];
			\draw[lego shape arm,lego shape arm shadow] (4.6,0.75) to[bend right=30] (3,0.5) to[bend right=30] (4.6,0.75) ;
		\end{scope}
		\draw[lego shape hand shadow] (3.34,0.5375) --++(-80:0.5) to[bend right=60] ++ (-80:1.8) --++ (100:0.5) to[bend left=90,looseness=2] ++ (10:1) --++ (-80:0.5) to[bend right=60] ++ (100:1.8) --++ (100:0.45) to[bend right=20] (3.34,0.5375)  ;
		\draw[lego shape hand] (3.34,0.5375) --++(-80:0.5) to[bend right=60] ++ (-80:1.8) --++ (100:0.5) to[bend left=110,looseness=3] ++ (10:1) --++ (-80:0.5) to[bend right=60] ++ (100:1.8) --++ (100:0.45) to[bend right=20] (3.34,0.5375) ;
		%arm 2
		\begin{scope}[xscale=-1]
			\draw[lego shape arm] (2.3175,4.6) {[rounded corners=\fpeval{\tkzlegoscale*6}mm] -- (3,4.6) -- (4.2,2.6)} -- (4.6,0.75) to[bend right=30] (3,0.5) -- cycle ;
			\begin{scope}
				\path[save path=\pathlegotikzarm] (3.34,0.5375) --++(-80:0.5) to[bend right=60] ++ (-80:1.8) --++ (100:0.5) to[bend left=110,looseness=3] ++ (10:1) --++ (-80:0.5) to[bend right=60] ++ (100:1.8) --++ (100:0.45) to[bend right=20] (3.34,0.5375) ;
				\clip[use path now=\pathlegotikzarm,invclip];
				\draw[lego shape arm,lego shape arm shadow] (4.6,0.75) to[bend right=30] (3,0.5) to[bend right=30] (4.6,0.75) ;
			\end{scope}
			\draw[lego shape hand shadow] (3.34,0.5375) --++(-80:0.5) to[bend right=60] ++ (-80:1.8) --++ (100:0.5) to[bend left=90,looseness=2] ++ (10:1) --++ (-80:0.5) to[bend right=60] ++ (100:1.8) --++ (100:0.45) to[bend right=20] (3.34,0.5375)  ;
			\draw[lego shape hand] (3.34,0.5375) --++(-80:0.5) to[bend right=60] ++ (-80:1.8) --++ (100:0.5) to[bend left=110,looseness=3] ++ (10:1) --++ (-80:0.5) to[bend right=60] ++ (100:1.8) --++ (100:0.45) to[bend right=20] (3.34,0.5375) ;
		\end{scope}
		%----nodes
		\coordinate (SHAPELEGOEYERIGHT) at (0.6,7.38) ;
		\coordinate (SHAPELEGOEYERIGHTSHADOW) at (0.6,7.5) ;
		\coordinate (SHAPELEGOEYELEFT) at (-0.6,7.38) ;
		\coordinate (SHAPELEGOEYELEFTSHADOW) at (-0.6,7.5) ;
		\coordinate (SHAPELEGOMOUTH) at (0,6.4) ;
		\coordinate (SHAPELEGOEYEBROWRIGHT) at (0.6,8.1) ;
		\coordinate (SHAPELEGOEYEBROWLEFT) at (-0.6,8.1) ;
		\coordinate (SHAPELEGOLOGO) at (0,2.5) ;
		\coordinate (SHAPELEGOHEIRCENTER) at (0,{5.45+3.385+0.5*0.7}) ;
		%-----decorations
		\ifboolKV[tkzshapelego]{empty}%
		{}%
		{%
			%---simple eyes
			\fill[black] (SHAPELEGOEYERIGHT) circle[x radius=0.3,y radius=0.35] ;
			\fill[black] (SHAPELEGOEYELEFT) circle[x radius=0.3,y radius=0.35] ;
			\fill[white] (SHAPELEGOEYERIGHTSHADOW) circle[x radius=0.1,y radius=0.125] ;
			\fill[white] (SHAPELEGOEYELEFTSHADOW) circle[x radius=0.1,y radius=0.125] ;
			%----simple mouth
			\begin{scope}[shift={(SHAPELEGOMOUTH)}]
				\filldraw[black] (-0.625,0.15) to[bend right=70] (0.625,0.15) to[bend left=20] cycle ;
			\end{scope}
			%----eyebrow man/woman + hairstyle
			\ifboolKV[tkzshapelego]{woman}%
			{%
				%----eyebrow
				\inttkzshapelegoeyebrowwoman{SHAPELEGOEYEBROWRIGHT}{SHAPELEGOEYERIGHT}%
				\inttkzshapelegoeyebrowwoman[-1]{SHAPELEGOEYEBROWLEFT}{SHAPELEGOEYELEFT}%
				%----hairstyle
				\ifnum\useKV[tkzshapelego]{hairstyle}=1\relax%
				\inttkzshapelegohairstylewomanA{SHAPELEGOHEIRCENTER}%
				\fi%
				\ifnum\useKV[tkzshapelego]{hairstyle}=2\relax%
				\inttkzshapelegohairstylemanA{SHAPELEGOHEIRCENTER}%
				\fi%
			}{}%
			\ifboolKV[tkzshapelego]{man}%
			{%
				%----eyebrow
				\inttkzshapelegoeyebrowman{SHAPELEGOEYEBROWRIGHT}{SHAPELEGOEYERIGHT}%
				\inttkzshapelegoeyebrowman[-1]{SHAPELEGOEYEBROWLEFT}{SHAPELEGOEYELEFT}%
				%----hairstyle
				\ifnum\useKV[tkzshapelego]{hairstyle}=1\relax%
				\inttkzshapelegohairstylemanA{SHAPELEGOHEIRCENTER}
				\fi%
				\ifnum\useKV[tkzshapelego]{hairstyle}=2\relax%
				\inttkzshapelegohairstylewomanA{SHAPELEGOHEIRCENTER}
				\fi%
			}%
			{}%
		}%
		%logo (auto or custom)
		\begin{scope}
			\clip (-2.25,0) rectangle (2.25,5) ;
			\ifboolKV[tkzshapelego]{display logo}%
			{%
				\node[inner sep=0pt,scale=\fpeval{1/(\tkzlegoscale)}] at (SHAPELEGOLOGO) {\resizebox{!}{\tkzlegoheightlogo}{\tkzshapelegologo}} ;
			}%
			{}%
			\ifboolKV[tkzshapelego]{custom logo}%
			{%
				\node[inner sep=0pt,scale=\fpeval{1/(\tkzlegoscale)}] at (SHAPELEGOLOGO) {\tkzshapelegologo} ;
			}%
			{}%
		\end{scope}
	\end{tikzpicture}%
}

\usepackage{codehigh}

\begin{document}

\begin{demohigh}[language=latex/latex2]
\definecolor{brickskin}{HTML}{FFDFC4}
\definecolor{brickjean}{HTML}{24496B}

\pictobrickfigurine%
[%
man,hairstyle=1,%
color skin=brickskin,
color hair=brown!75!black,
color sweat=white,
color pant=brickjean,
color foot=brickjean!50!black,
display logo,scale logo=0.8,logo={\openmoji{snake}}
]%
{5cm}%
\end{demohigh}

\vfill

{\footnotesize\ttfamily{CC BY-SA 4.0}}

\end{document}