%!TEX pdflatex

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{amssymb}
\usepackage{lipsum}

\ExplSyntaxOn

% Définition des variables et longueurs
\fp_new:N \l_tikz_ornements_hstretch_fp
\dim_new:N \l_tikz_ornements_linewidth_dim
\dim_new:N \l_tikz_ornements_vsize_dim
\dim_new:N \l_tikz_ornements_border_dim
%\dim_set:Nn \l_tikz_ornements_border_dim { 4mm }
\tl_new:N \l_tikz_ornements_color_tl
\bool_new:N \l_tikz_ornements_altdeco_bool

% Commande pour dessiner un coin
\cs_new_protected:Npn \inttikzorncorner:nn #1#2
{
	\begin{scope}[
		line~width={\dim_use:N \l_tikz_ornements_linewidth_dim},
		shift={(#1)},
		#2,
		color={\tl_use:N \l_tikz_ornements_color_tl},
		transform~shape
		]
		% Décoration principale
		\draw (0,{\dim_use:N \l_tikz_ornements_vsize_dim}) -- (0, {\dim_eval:n { 0.4 \l_tikz_ornements_border_dim }}) -- (\dim_eval:n { 0.8 \l_tikz_ornements_border_dim}, \dim_eval:n {0.4 \l_tikz_ornements_border_dim}) |-++ (\dim_eval:n { -0.4 \l_tikz_ornements_border_dim }, \dim_eval:n { 0.4 \l_tikz_ornements_border_dim }) |- (\fp_eval:n {\l_tikz_ornements_hstretch_fp * \l_tikz_ornements_vsize_dim}pt, 0);
		% Carré
		\draw (\dim_eval:n { 0.2 \l_tikz_ornements_border_dim }, \dim_eval:n { 0.2 \l_tikz_ornements_border_dim }) rectangle (\dim_use:N \l_tikz_ornements_border_dim, \dim_use:N \l_tikz_ornements_border_dim);
		% Décoration secondaire verticale
		\draw (\dim_eval:n { 0.2 \l_tikz_ornements_border_dim }, {\dim_use:N \l_tikz_ornements_border_dim + 1.25mm}) -- (\dim_eval:n { 0.2 \l_tikz_ornements_border_dim }, {\dim_use:N \l_tikz_ornements_vsize_dim - 1.25mm});
		% Décoration secondaire horizontale
		\draw (\dim_use:N \l_tikz_ornements_border_dim + 1.25mm, \dim_eval:n { 0.2 \l_tikz_ornements_border_dim }) -- ({\fp_eval:n {\l_tikz_ornements_hstretch_fp * \l_tikz_ornements_vsize_dim}pt - 1.25mm}, \dim_eval:n { 0.2 \l_tikz_ornements_border_dim });
	\end{scope}
}

% Style tcolorbox
\tcbset{
	tikz~bordures~ornements/.style={
		enhanced,
		frame~empty,
		boxsep=0pt,
		top=0.15mm+\dim_use:N \l_tikz_ornements_border_dim,
		left=0.15mm+\dim_use:N \l_tikz_ornements_border_dim,
		right=0.15mm+\dim_use:N \l_tikz_ornements_border_dim,
		bottom=0.15mm+\dim_use:N \l_tikz_ornements_border_dim,
		opacityfill=0,
		finish~unbroken={
			\bool_if:NTF \l_tikz_ornements_altdeco_bool
			{
				\draw[line~width=\dim_use:N \l_tikz_ornements_linewidth_dim, \tl_use:N \l_tikz_ornements_color_tl!25, opacity=0.5] ([shift={(\dim_use:N \l_tikz_ornements_border_dim, \dim_use:N \l_tikz_ornements_border_dim)}]frame.south~west) rectangle ([shift={(-\dim_use:N \l_tikz_ornements_border_dim, -\dim_use:N \l_tikz_ornements_border_dim)}]frame.north~east);
			}{}
			\begin{scope}%south west
				\clip ([xshift={\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }}, yshift={\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }}]frame.south~west) -- ([xshift={\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }}]frame.west) -- ([yshift={\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }}]frame.south) -- cycle;
				\inttikzorncorner:nn {frame.south~west} {}
			\end{scope}
			\begin{scope}
				\clip ([xshift=\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }, yshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }]frame.north~west) -- ([xshift=\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }]frame.west) -- ([yshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }]frame.north) -- cycle;
				\inttikzorncorner:nn {frame.north~west} {yscale=-1}
			\end{scope}
			\begin{scope}
				\clip ([xshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }, yshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }]frame.north~east) -- ([xshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }]frame.east) -- ([yshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }]frame.north) -- cycle;
				\inttikzorncorner:nn {frame.north~east} {scale=-1}
			\end{scope}
			\begin{scope}
				\clip ([xshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }, yshift=\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }]frame.south~east) -- ([xshift=\dim_eval:n { 0.5 \l_tikz_ornements_linewidth_dim }]frame.east) -- ([yshift=\dim_eval:n { -0.5 \l_tikz_ornements_linewidth_dim }]frame.south) -- cycle;
				\inttikzorncorner:nn {frame.south~east} {xscale=-1}
			\end{scope}
		}
	}
}

% Définition des clés
\keys_define:nn { tcboxornements }
{
	v~size~deco .dim_set:N      = \l_tikz_ornements_vsize_dim,
	linewidth~deco .dim_set:N   = \l_tikz_ornements_linewidth_dim,
	color~deco .tl_set:N        = \l_tikz_ornements_color_tl,
	alt~deco .bool_set:N        = \l_tikz_ornements_altdeco_bool,
	h~stretch~deco .fp_set:N    = \l_tikz_ornements_hstretch_fp,
	inner~size~deco .dim_set:N  = \l_tikz_ornements_border_dim,
	v~size~deco .initial:n      = {1.5cm},
	linewidth~deco .initial:n   = {0.2mm},
	color~deco .initial:n       = {black},
	alt~deco .initial:n         = {false},
	h~stretch~deco .initial:n   = {1},
	inner~size~deco .initial:n  = {3.6mm}
}

% Environnement tcboxornements
\NewDocumentEnvironment{tcboxornements}{ O{} m }
{
	\keys_set:nn { tcboxornements } {#1}
	%\colorlet{tcboxornements@color}{\tl_use:N \l_tikz_ornements_color_tl}
	\tcolorbox[tikz~bordures~ornements, #2]
}
{
	\endtcolorbox%
}

\ExplSyntaxOff

\begin{document}

\begin{tcboxornements}[alt deco,v size deco = 1.5cm , h stretch deco = 2 , color deco = blue , alt deco]{}
	\lipsum[1]
\end{tcboxornements}

\begin{tcboxornements}{}
	\lipsum[1]
\end{tcboxornements}

\begin{tcboxornements}[alt deco,v size deco=2cm,h stretch deco = 1.75]{}
	\lipsum[1]
\end{tcboxornements}

\ExplSyntaxOn
\keys_define:nn { tcboxornements }
{
	v~size~deco .initial:n        = {2cm},
	linewidth~deco .initial:n     = {0.3mm},
	color~deco .initial:n         = {pink},
	alt~deco .initial:n           = {false},
	h~stretch~deco .initial:n     = {1.75},
	inner~size~deco .initial:n    = {2mm}
}
\ExplSyntaxOff

\begin{tcboxornements}{}
	\lipsum[2][1]
\end{tcboxornements}

\begin{tcboxornements}{center,width=12cm,halign=center,bottom=1.5mm,top=1.5mm,fontupper=\LARGE\sffamily,colupper=red!50!black}
	CHAPITRE 01 : Éléments de logique
\end{tcboxornements}


\end{document}