% !TeX TS-program = pdflatex


\documentclass[french,a4paper,11pt]{article}
\usepackage{babel}
\usepackage[margin=1.5cm]{geometry}
\usepackage{hvlogos}
\usepackage[table,svgnames]{xcolor}
\usepackage{tikz,pgffor}
\usepackage{simplekv}
\setlength{\parindent}{0pt}

\begin{document}

\part*{Essai d'outils géométriques en \TikZ}

\section{Équerre, règle}

\defKV[PLgeom]{%
	echelle=\def\EQechelle{#1},%
	echelleangle=\def\EQechangle{#1},%
	couleur=\def\EQcouleur{#1},%
	x=\def\EQposx{#1},%
	y=\def\EQposy{#1},%
	angle=\def\EQangle{#1}
}

\setKVdefault[PLgeom]{%
	echelle=1,%
	echelleangle=0.8,%
	couleur=red,%
	x=0,%
	y=0,%
	angle=0,%
	affval=true
}

\newcommand\equerre[1][]{%
	\useKVdefault[PLgeom]
	\setKV[PLgeom]{#1}
	\begin{scope}[shift={(\EQposx,\EQposy)},rotate=\EQangle,scale=\EQechelle]
		\draw[thick,\EQcouleur] (0,0)--(1,0)--(0,1.8)--cycle;
		\draw[thick,\EQcouleur] (0.2,0.2)--(0.65,0.2)--(0.2,1)--cycle;
		\foreach \x in {0,0.1,...,1} {\draw[\EQcouleur,thick] (\x,0)--++(0,1.5pt) ;}
		\foreach \x in {0,0.5} {\draw[\EQcouleur,thick] (\x,0)--++(0,2pt) ;}
		\foreach \y in {0,0.1,...,1.7} {\draw[\EQcouleur,thick] (0,\y)--++(1.5pt,0) ;}
		\foreach \y in {0,0.5,1,1.5} {\draw[\EQcouleur,thick] (0,\y)--++(2pt,0) ;}
	\end{scope}
}

\newcommand\regle[1][]{%
	\useKVdefault[PLgeom]
	\setKV[PLgeom]{#1}
	\begin{scope}[shift={(\EQposx,\EQposy)},rotate=\EQangle,scale=\EQechelle]
		\draw[thick,\EQcouleur] (0,0)--(2,0)--(2,-0.3)--(0,-0.3)--cycle ;
		\foreach \y in {0,0.1,...,2} {\draw[\EQcouleur,thick] (\y,0)--++(0,-1.5pt) ;}
		\foreach \y in {0,0.5,...,2} {\draw[\EQcouleur,thick] (\y,0)--++(0,-2pt) ;}
	\end{scope}
}

\newcommand{\rapporteur}[1][]{%
	\useKVdefault[PLgeom]
	\setKV[PLgeom]{#1}
	\begin{scope}[shift={(\EQposx,\EQposy)},rotate=\EQangle,scale=\EQechelle]
		\draw[thick,\EQcouleur] (-3.75,0)--(-3.75,-0.75)--(3.75,-0.75)--(3.75,0) ;
		\draw[thick,\EQcouleur] (-2.25,0)--(-0.5,0) ;
		\draw[thick,\EQcouleur] (0.5,0)--(2.25,0) ;
		\draw[thick,\EQcouleur] (-0.175,0)--(0.175,0) (0,-0.175)--(0,0.175) ;
		\draw[thick,\EQcouleur] (3.75,0) arc (0:180:3.75) ;
		\draw[thick,\EQcouleur] (2.25,0) arc (0:180:2.25) ;
		\draw[thick,\EQcouleur] (0.5,0) arc (0:180:0.5) ;
		%grad ext
		\foreach \i in {0,1,...,180} {\draw[\EQcouleur] (\i:3.55)--(\i:3.75) ;}
		\foreach \i in {0,10,...,180} {\draw[\EQcouleur] (\i:3.4)--(\i:3.75) ;}
		\foreach \i in {0,5,...,180} {\draw[\EQcouleur] (\i:3.45)--(\i:3.75) ;}
		%grad int
		\foreach \i in {0,10,...,180} {\draw[\EQcouleur] (\i:2.45)--(\i:2.25) ;}
		\foreach \i in {0,5,...,180} {\draw[\EQcouleur] (\i:2.35)--(\i:2.25) ;}
		%valeurs si booléen
		\ifboolKV[PLgeom]{affval}
			{%
				\foreach \i in {0,10,...,180} {\draw[\EQcouleur] (\i:3.2) node[rotate=\EQangle,scale=\fpeval{\EQechelle*\EQechangle},font=\tiny] {\i} ;}
				\foreach \i in {0,10,...,180} {\draw[\EQcouleur] (\i:2.65) node[rotate=\EQangle,scale=\fpeval{\EQechelle*\EQechangle},font=\tiny] {\inteval{180-\i}} ;}%
			}{}
	\end{scope}
}

\textbf{Équerre} : be base, l'angle droit est placé en $(0\,;\,0)$.

\smallskip

\textbf{Règle} : de base, le \og début \fg{} est placé en $(0\,;\,0)$.

\medskip

\hfill\begin{tikzpicture}[x=0.75cm,y=0.75cm]
	\draw[xstep=1,ystep=1,lightgray] (-4,-4) grid (6,4) ;
	\foreach \x in {-4,-3,...,6} \draw[lightgray] (\x,-4)--++(0,-3pt) node[font=\scriptsize,below] {\x} ;
	\foreach \y in {-4,-3,...,4} \draw[lightgray] (-4,\y)--++(-3pt,0) node[font=\scriptsize,left] {\y} ;
	\filldraw (0,0) circle[radius=2pt] (-2,-3) circle[radius=2pt] (2,2) circle[radius=2pt] ;
	%essai décalé
	\equerre
	\draw (0,0) node[red,below,font=\tiny] {\verb|\equerre|} ;
	\equerre[x=-2,y=-3,angle=45,couleur=ForestGreen]
	\draw (-4,-3) node[ForestGreen,below right,font=\tiny] {\verb|\equerre[x=-2,y=-3,angle=45,couleur=ForestGreen]|} ;
	\equerre[x=2,y=2,angle=-60,couleur=DarkBlue,echelle=2]
	\draw (-4,3.85) node[DarkBlue,below right,font=\tiny] {\verb|\equerre[x=2,y=2,angle=-60,couleur=DarkBlue,echelle=2]|} ;
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}[x=0.75cm,y=0.75cm]
	\draw[xstep=1,ystep=1,lightgray] (-4,-4) grid (5,4) ;
	\foreach \x in {-4,-3,...,5} \draw[lightgray] (\x,-4)--++(0,-3pt) node[font=\scriptsize,below] {\x} ;
	\foreach \y in {-4,-3,...,4} \draw[lightgray] (-4,\y)--++(-3pt,0) node[font=\scriptsize,left] {\y} ;
	\filldraw (0,0) circle[radius=2pt] (-2,-3) circle[radius=2pt] (2,2) circle[radius=2pt] ;
	%essai décalé
	\regle
	\draw (0,0) node[red,above,font=\tiny] {\verb|\regle|} ;
	\regle[x=-2,y=-3,angle=45,couleur=ForestGreen]
	\draw (-4,-3.15) node[ForestGreen,below right,font=\tiny] {\verb|\regle[x=-2,y=-3,angle=45,couleur=ForestGreen]|} ;
	\regle[x=2,y=2,angle=-60,couleur=DarkBlue,echelle=2.25]
	\draw (4.75,2) node[DarkBlue,above left,font=\tiny] {\verb|\regle[x=2,y=2,angle=-60,couleur=DarkBlue,echelle=2.25]|} ;
\end{tikzpicture}\hfill~

\section{Rapporteur}

\textbf{Rapporteur} : de base, le \og centre (+) \fg{} est placé en $(0\,;\,0)$.

\medskip

\hfill\begin{tikzpicture}[x=0.75cm,y=0.75cm]
	\draw[xstep=1,ystep=1,lightgray] (-4,-8) grid (12,4) ;
	\foreach \x in {-4,-3,...,12} \draw[lightgray] (\x,-8)--++(0,-3pt) node[font=\scriptsize,below] {\x} ;
	\foreach \y in {-8,-7,...,4} \draw[lightgray] (-4,\y)--++(-3pt,0) node[font=\scriptsize,left] {\y} ;
	\filldraw (0,0) circle[radius=2pt] (-2,-5) circle[radius=2pt] (8,-2) circle[radius=2pt] ;
	%essai décalé
	\rapporteur
	\draw (0,-1) node[red,below,font=\tiny] {\verb|\rapporteur|} ;
	\rapporteur[x=-2,y=-5,angle=-45,couleur=ForestGreen,echelle=0.5]
	\draw (-4,-6.5) node[ForestGreen,below right,font=\tiny] {\verb|\rapporteur[x=-2,y=-5,angle=-45,couleur=ForestGreen,echelle=0.5]|} ;
	\rapporteur[x=8,y=-2,angle=30,couleur=DarkBlue,echelle=0.75,affval=false]
	\draw (6,-4) node[DarkBlue,below,font=\tiny] {\verb|\rapporteur[x=8,y=-2,angle=30,couleur=DarkBlue,echelle=0.75,affval=false]|} ;
\end{tikzpicture}\hfill~


\end{document}