%autotex% Titre: Tests avec TiKZ

\paragraph{Sources}
Surtout \href{http://www.altermundus.fr/pages/examples.html}{www.altermundus.fr/pages/examples.html}
et \href{http://math.et.info.free.fr/TikZ/bdd/TikZ-Impatient.pdf}{TikZ pour l'impatient}.

\section{Page de brouillon} % (fold)
\label{sec:page_de_brouillon}

% Définition des nouvelles options xmin, xmax, ymin, ymax
% Valeurs par défaut : -3, 3, -3, 3
\tikzset{
	xmin/.store in=\xmin, xmin/.default=-3, xmin=-3,
	xmax/.store in=\xmax, xmax/.default=3, xmax=3,
	ymin/.store in=\ymin, ymin/.default=-3, ymin=-3,
	ymax/.store in=\ymax, ymax/.default=3, ymax=3,
}
% Commande qui trace la grille entre (xmin,ymin) et (xmax,ymax)
\newcommand {\grille}
{\draw[help lines] (\xmin,\ymin) grid (\xmax,\ymax);}
% Commande \axes
\newcommand {\axes} {
	\draw[->] (\xmin,0) -- (\xmax,0);
	\draw[->] (0,\ymin) -- (0,\ymax);
}
% Commande qui limite l’affichage à (xmin,ymin) et (xmax,ymax)
\newcommand {\fenetre}
	{\clip (\xmin,\ymin) rectangle (\xmax,\ymax);}


\begin{figure}[htbp]
	\centering
	\begin{tikzpicture} %% [scale=3]
		\draw [samples=300, domain=0:9, scale=1.0] plot (20*\x:\x);
	\end{tikzpicture}
	\caption{Espace brouillon}
\end{figure}

\begin{figure}[htbp]
	\centering
	\begin{tikzpicture} [xmin=-2,xmax=2,ymin=0,ymax=5]
		\grille \axes \fenetre
		\draw plot[smooth] (\x,\x^2);
	\end{tikzpicture}
	\caption{Macros xmin,xmax,ymin,ymax, et grille, axes, fenetre}
\end{figure}


\newpage{}
% section page_de_brouillon (end)

\section{Un programme ?} % (fold)
\label{sec:un_programme_}

\begin{figure}[htbp]
	\centering
	\begin{tikzpicture}
		% style des nœuds
		\tikzstyle{debutfin}=[ellipse,draw,text=red]
		\tikzstyle{instruct}=[rectangle,draw,fill=yellow!50]
		\tikzstyle{test}=[diamond, aspect=2.5,thick,
		draw=blue,fill=yellow!50,text=blue]
		\tikzstyle{es}=[rectangle,draw,rounded corners=4pt,fill=blue!25]
		% style des flèches
		\tikzstyle{suite}=[->,>=stealth',thick,rounded corners=4pt]
		% placement des nœuds
		\node[debutfin] (debut) at (-2,5) {Début};
		\node[es] (lire) at (-2,4) {Lire un entier positif $N$};
		\node[test] (test) at (0,0) {$N>0$ \ ?};
		\node[instruct] (init) at (-2,2.5) {$S\leftarrow 0$};
		\node[instruct] (plus) at (0,-2.5) {$S\leftarrow S+N$};
		\node[instruct] (moins) at (0,-3.5) {$N\leftarrow N-1$};
		\node[es] (afficher) at (-4,-2) {Afficher la somme $S$};
		\node[debutfin] (fin) at (-4,-3) {Fin};
		% Placement des flèches
		\draw[suite] (debut) -- (lire);
		\draw[suite] (lire) -- (init);
		\draw[suite] (init) -- (test.north);
		\draw[suite] (test) -- (plus) node[midway,fill=white]{oui};
		\draw[suite] (plus) -- (moins);
		\draw[suite] (moins)|-(3,-4.5) |- (1,1.5)--(test.north);
		\draw[suite] (test)-|(afficher)node[near start,fill=white]{non};
		\draw[suite] (afficher) -- (fin);
	\end{tikzpicture}
	\caption{Un programme ?}
\end{figure}


% section un_programme_ (end)


\section{Premier test} % (fold)
\label{sec:premier_test}

\begin{tikzpicture}[remember picture,overlay]
	\node [rotate=60,scale=10,text opacity=0.3]
	at (current page.center) {Ti\textit{\color{orange}k}Z};
\end{tikzpicture}


\begin{figure}[htbp]
	\centering
\begin{tikzpicture}[scale=3]
   \draw (0,0) -- (1,1) ;
\end{tikzpicture}
	\caption{Un segment}
\end{figure}

\newpage{}
% section premier_test (end)

\section{Second test} % (fold)
\label{sec:second_test}

\begin{figure}[htbp]
	\centering
	\def\arete{3} \def\epaisseur{5} \def\rayon{2}
	\newcommand{\ruban}{(0,0)
		++(0:0.57735*\arete-0.57735*\epaisseur+2*\rayon)
		++(-30:\epaisseur-1.73205*\rayon)
		arc (60:0:\rayon) -- ++(90:\epaisseur)
		arc (0:60:\rayon) -- ++(150:\arete)
		arc (60:120:\rayon) -- ++(210:\epaisseur)
		arc (120:60:\rayon) -- cycle}

	\begin{tikzpicture}[very thick,top color=white,bottom color=gray]
		\shadedraw \ruban;
		\shadedraw [rotate=120] \ruban;
		\shadedraw [rotate=-120] \ruban;
		\draw (-60:4) node[scale=5,rotate=30]{Ti{\color{orange}\textit{k}}Z};
		\draw (180:4) node[scale=3,rotate=-90]{l’impatient};
		\clip (0,-6) rectangle (6,6); % pour croiser
		\shadedraw \ruban;
		\draw (60:4) node [gray,xscale=-3,yscale=3,rotate=30]{pour};
	\end{tikzpicture}
	\caption{Symbole ``TikZ pour l’impatient''}
\end{figure}

\newpage{}
% section second_test (end)

\section{Troisième test} % (fold)
\label{sec:troisi_me_test}

To multiply two matrices, the first matrix must have the same number of rows (p) as the second matrix has columns (q).  In other words, p of the first matrix must equal q of the second matrix. In general terms, a matrix C which is a product of two matrices, A and B, will have elements given by the following 
\[c_{ij}=\sum_{k=1}^p a_{ik}b_{kj}\]
 where $i$ = ith row and $j$ = jth column

\begin{figure}[htbp]
	\centering
\begin{tikzpicture}[>=latex]
	% unit
	\newcommand{\myunit}{1.2 cm}
	% the styles
	\tikzset{node style sp/.style={draw,circle,minimum size=\myunit}}  
	\tikzset{node style ge/.style={circle,minimum size=\myunit}}
	\tikzset{arrow style mul/.style={draw,sloped,midway,fill=white}}
	\tikzset{arrow style plus/.style={midway,sloped,fill=white}}
	% defintion of matrices
	\matrix (A) [matrix of math nodes,%
	             nodes = {node style ge},%
	             left delimiter  = (,%
	             right delimiter = )] at (0,0)
	{%
	  a_{11} &\ldots & a_{1k} & \ldots & a_{1p}  \\ 
	    \vdots & \ddots & \vdots & \vdots & \vdots \\
	  \node[node style sp] {a_{i1}};& \ldots%
	         & \node[node style sp] {a_{ik}};%
	                  & \ldots%
	                           & \node[node style sp] {a_{ip}}; \\ 
	  \vdots & \vdots& \vdots & \ddots & \vdots  \\
	  a_{n1}& \ldots & a_{nk} & \ldots & a_{np}  \\ 
	}; 
	\node [draw,below] at (A.south) { $A$ : \textcolor{red}{$n$ rows} $p$ columns};
	\matrix (B) [matrix of math nodes,%
	             nodes = {node style ge},%
	             left delimiter  = (,%
	             right delimiter =)] at (7*\myunit,7*\myunit)
	{% 
	  b_{11} &  \ldots& \node[node style sp] {b_{1j}};%
	                  & \ldots & b_{1q}  \\ 
	  \vdots& \ddots & \vdots & \vdots & \vdots \\
	  b_{k1} &  \ldots& \node[node style sp] {b_{kj}};%
	                  & \ldots & b_{kq}  \\ 
	  \vdots& \vdots & \vdots & \ddots & \vdots \\
	  b_{p1} &  \ldots& \node[node style sp] {b_{pj}};%
	                  & \ldots & b_{pq}  \\ 
	};
	\node [draw,above] at (B.north) { $B$ : $p$ rows \textcolor{red}{$q$ columns}}; 
	% matrice résultat
	\matrix (C) [matrix of math nodes,%
	             nodes = {node style ge},%
	             left delimiter  = (,%
	             right delimiter = )] at (7*\myunit,0)
	{% 
	  c_{11} & \ldots& c_{1j} & \ldots & c_{1q} \\ 
	  \vdots& \ddots & \vdots & \vdots & \vdots \\
	    c_{i1}& \ldots & \node[node style sp,red] {c_{ij}};%
	                  & \ldots & c_{iq} \\ 
	  \vdots& \vdots & \vdots & \ddots & \vdots \\
	  c_{n1}& \ldots & c_{nk} & \ldots & c_{nq} \\ 
	}; 
	\node [draw,below] at (C.south) {$ C=A\times B$ : \textcolor{red}{$n$ rows}  \textcolor{red}{$q$ columns}};
	% arrows
	\draw[blue] (A-3-1.north) -- (C-3-3.north);
	\draw[blue] (A-3-1.south) -- (C-3-3.south);
	\draw[blue] (B-1-3.west)  -- (C-3-3.west);
	\draw[blue] (B-1-3.east)  -- (C-3-3.east);
	\draw[<->,red](A-3-1) to[in=180,out=90] (B-1-3)%
	      node[arrow style mul] (x) {$a_{i1}\times b_{1j}$};
	\draw[<->,red](A-3-3) to[in=180,out=90](B-3-3)%
	      node[arrow style mul] (y) {$a_{ik}\times b_{kj}$};
	\draw[<->,red](A-3-5) to[in=180,out=90](B-5-3)%
	      node[arrow style mul] (z) {$a_{ip}\times b_{pj}$};
	\draw[red,->] (x) to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (y)%
	                  to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (z);
	                  %
	                  % to (C-3-3.north west);
	\draw[->,red,decorate,decoration=zigzag] (z) -- (C-3-3.north west);
\end{tikzpicture}
	\caption{Produit de matrice}
\end{figure}

\newpage{}
% section troisi_me_test (end)

\section{Quatrième Test} % (fold)
\label{sec:quatri_me_test}

\begin{figure}[htbp]
	\centering
	\newcounter{density}
	\setcounter{density}{20}
	\begin{tikzpicture}

		\def\couleur{blue}
		\path[coordinate] ( 0 , 0)   coordinate(A)
		                ++( 60:12cm) coordinate(B)
		                ++(-60:12cm) coordinate(C);
		\draw[fill=\couleur!\thedensity] (A) -- (B) -- (C) -- cycle;
		\foreach \x in {1,...,15}{%
		  \pgfmathsetcounter{density}{\thedensity+10}
		  \setcounter{density}{\thedensity}
		  \path[coordinate] coordinate(X) at (A){};
		  \path[coordinate] (A) -- (B) coordinate[pos=.15](A)
		                        -- (C) coordinate[pos=.15](B)
		                        -- (X) coordinate[pos=.15](C);
		  \draw[fill=\couleur!\thedensity] (A)--(B)--(C)--cycle;}
	\end{tikzpicture}
	\caption{Triangle}
\end{figure}


\newpage{}
% section quatri_me_test (end)

\section{Cinquième test} % (fold)
\label{sec:cinqui_me_test}

\begin{figure}[htbp]
	\centering
	\newcounter{j}
	\begin{tikzpicture}[scale=10,>=latex']  
	    \draw[color=blue,samples at={0,0.01,...,1.07}] plot (\x,{cos(\x r)});  
	    \draw[color=green](0,0)--(1,1);
	    \draw[->](0,0)--(0,1) node[above]{$y$};
	    \draw[->](0,0)--(1,0) node[right]{$x$};
	    \newcounter{cnt}
	    \newcommand{\x}{.2}
	    \foreach \i in {1,...,7}{%
	       \pgfmathcos{\x r}
	       \let\y\pgfmathresult
	       \draw[color=magenta](\x,\x)--(\x,\y)--(\y,\y);
	       \draw[color=orange,dotted,line width=0.8pt]%
	            (\x,\x)--(\x,0) node[below=8pt]{$u_\i$};
	       \pgfmathsetcounter{j}{\i+1}
	       \draw[color=blue,dotted,line width=0.8pt]%
	            (\x,\y)--(0,\y) node[left=8pt] {$u_\thej$};
	       \global\let\x\y}
	\end{tikzpicture}
	\caption{$f(x)=\cos (x)$}
\end{figure}


% avec \usetikzlibrary{fadings} en préambule pour le dégradé
	\newcommand{\Fin}{node[xshift=-1.5ex,rotate=10]{F}
	node[rotate=170]{i}
	node[xshift=1.5ex,rotate=45]{n}}

\begin{figure}[htbp]
	\centering
	\begin{tikzpicture}[scale=10,transform shape]
		\draw (0,0) \Fin;
		\draw (-1em,-1ex) -- (1em,-1ex);
		\path[scope fading=south] (-1em,-0.25em) rectangle (1em,-3.75ex);
		\draw[yscale=-1] (0,2ex) \Fin;
	\end{tikzpicture}
\end{figure}


\newpage{}
% section cinqui_me_test (end)