
%\chapter{MPSI}
\Classe{2nd}
\MySection[AP - Algo]{A.P. }{semaine}{}
%\thispagestyle{landscape}

Écrire des algorithmes (ou le code) permattant de produire les dessins suivants (avec Algobox)

\vspace{1em}
\newcommand{\scale}{0.3}
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \k in {0,...,\n}{
\draw[thick] (\k,0)--(\k,\n);
};
\node[yshift=1.5ex] at (5,10) {Dessin 1};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{30}
\foreach \k in {0,...,\n}{
\pgfmathsetmacro\K{\k*10/\n}
\draw[thick] (\K,0)--(\K,10);
};
\node[yshift=1.5ex] at (5,10) {Dessin 2};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \k in {0,...,\n}{
\draw[thick] (\k,\k)--(\k,\n);
};
\node[yshift=1.5ex] at (5,10) {Dessin 3};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \k in {0,...,\n}{
\draw[thick] (0,0)--(\n,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 4};
\end{tikzpicture}\hfill
% \begin{tikzpicture}[scale=\scale]
% \pgfmathsetmacro\n{10}
% \foreach \k in {0,...,\n}{
% \draw[thick] (\k,0)--(\k,\k);
% \draw[thick] (0,\k)--(\k,\k);
% };
% \end{tikzpicture}\hfill

\vspace{1em}
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \k in {0,...,\n}{
\draw[thick] (\k,0)--(\k,\k);
\draw[thick] (0,\k)--(\k,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 5};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \k in {0,...,\n}{
\draw[thick] (0,0)--(10,\k);
\draw[thick] (0,0)--(\k,10);
};
\node[yshift=1.5ex] at (5,10) {Dessin 6};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \K in {0,...,\n}{
\pgfmathsetmacro\k{\K*10/\n}
\draw[thick] (0,\k)--(10,10-\k);
\draw[thick] (\k,0)--(10-\k,10);
};
\node[yshift=1.5ex] at (5,10) {Dessin 7};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \K in {0,...,\n}{
\pgfmathsetmacro\k{\K*10/\n}
\draw[thick] (\k,\k)--(\k,10-\k);
\draw[thick] (\k,\k)--(10-\k,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 8};
\end{tikzpicture}\hfill

\vspace{1em}
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \K in {0,...,\n}{
\pgfmathsetmacro\k{\K*10/\n}
\draw[thick] (\k,0)--(10,\k);
%\draw[thick] (\k,\k)--(10-\k,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 9};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{20}
\foreach \K in {0,...,\n}{
\pgfmathsetmacro\k{\K*10/\n}
\draw[thin] (\k,0)--(10,\k);
%\draw[thick] (\k,\k)--(10-\k,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 10};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \K in {0,...,\n}{
\pgfmathsetmacro\k{\K*10/\n}
\draw[thick] (\k,0)--(10,\k);
\draw[thick] (10,\k)--(10-\k,10);
\draw[thick] (10-\k,10)--(0,10-\k);
\draw[thick] (0,10-\k)--(\k,0);
%\draw[thick] (\k,\k)--(10-\k,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 11};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale]
\pgfmathsetmacro\n{10}
\foreach \K in {0,...,\n}{
\pgfmathsetmacro\k{\K*5/\n}
\draw[thick] (5+\k,5)--(10,5+\k);
\draw[thick] (10-\k,10)--(5,10-\k);
\draw[thick] (\k,0)--(5,\k);
\draw[thick] (5-\k,5)--(0,5-\k);
\draw[thick] (5,\k+5)--(5-\k,10);
\draw[thick] (0,10-\k)--(\k,5);
\draw[thick] (10,\k)--(10-\k,5);
\draw[thick] (5,5-\k)--(5+\k,0);
%\draw[thick] (\k,\k)--(10-\k,\k);
};
\node[yshift=1.5ex] at (5,10) {Dessin 12};
\end{tikzpicture}\hfill

\vspace{2em}
\begin{minipage}{0.4\textwidth}
Soient $A_0$, $B_0$, $C_0$, $D_0$ un carré et $k\in ]0,1[$ pour tout $n \in \N$
on définit $A_{n+1}$, $B_{n+1}$, $C_{n+1}$, $D_{n+1}$ par
$\st{\lra}{A_nA_{n+1}}=k\cdot \st{\lra}{A_nB_n}$, $\st{\lra}{B_nB_{n+1}}=k\cdot
\st{\lra}{B_nC_n}$, $\st{\lra}{C_nC_{n+1}}=k\cdot \st{\lra}{C_nD_n}$ et
$\st{\lra}{D_nD_{n+1}}=k\cdot \st{\lra}{D_nA_n}$. 

Ecrire un programe prenant comme argument un entier non nul $N$, et un réel $k
\in ]0;1[$ et dessinant tous les carrés $A_nB_nC_nD_n$ pour $n$ variant de $0$ à
$N$ :\end{minipage}\hfill
\begin{tikzpicture}[scale=\scale,baseline=(current bounding box).center]
\pgfmathsetmacro\XA{0}
\pgfmathsetmacro\YA{0}
\pgfmathsetmacro\XB{10}
\pgfmathsetmacro\YB{0}
\pgfmathsetmacro\XD{0}
\pgfmathsetmacro\YD{10}
\pgfmathsetmacro\XC{10}
\pgfmathsetmacro\YC{10}
\pgfmathsetmacro\XAa{0}
\pgfmathsetmacro\YAa{0}
\pgfmathsetmacro\XBa{10}
\pgfmathsetmacro\YBa{0}
\pgfmathsetmacro\XCa{0}
\pgfmathsetmacro\YCa{10}
\pgfmathsetmacro\XDa{10}
\pgfmathsetmacro\YDa{10}
\pgfmathsetmacro\N{5}
\pgfmathsetmacro\k{0.3}
\foreach \n in {1,...,\N}{
\draw (\XA,\YA)--(\XB,\YB)--(\XC,\YC)--(\XD,\YD)--(\XA,\YA);

\pgfmathparse{\XA+\k*(\XB-\XA)}
\let\XAa=\pgfmathresult
\pgfmathparse{\YA+\k*(\YB-\YA)}
\let\YAa=\pgfmathresult
%
\pgfmathparse{\XB+\k*(\XC-\XB)}
\let\XBa=\pgfmathresult
\pgfmathparse{\YB+\k*(\YC-\YB)}
\let\YBa=\pgfmathresult
%
\pgfmathparse{\XC+\k*(\XD-\XC)}
\let\XCa=\pgfmathresult
\pgfmathparse{\YC+\k*(\YD-\YC)}
\let\YCa=\pgfmathresult
\pgfmathparse{\XD+\k*(\XA-\XD)}
\let\XDa=\pgfmathresult
\pgfmathparse{\YD+\k*(\YA-\YD)}
\global\let\YDa=\pgfmathresult
\global\let\XA=\XAa
\global\let\YA=\YAa
\global\let\XB=\XBa
\global\let\YB=\YBa
\global\let\YC=\YCa
\global\let\XC=\XCa
\global\let\XD=\XDa
\global\let\YD=\YDa
};
\node[yshift=-1.5ex] at (5,0) {$N=\N$ et $k=\k$};
\end{tikzpicture}\hfill
\begin{tikzpicture}[scale=\scale,baseline=(current bounding box).center]
\pgfmathsetmacro\XA{0}
\pgfmathsetmacro\YA{0}
\pgfmathsetmacro\XB{10}
\pgfmathsetmacro\YB{0}
\pgfmathsetmacro\XD{0}
\pgfmathsetmacro\YD{10}
\pgfmathsetmacro\XC{10}
\pgfmathsetmacro\YC{10}
\pgfmathsetmacro\XAa{0}
\pgfmathsetmacro\YAa{0}
\pgfmathsetmacro\XBa{10}
\pgfmathsetmacro\YBa{0}
\pgfmathsetmacro\XCa{0}
\pgfmathsetmacro\YCa{10}
\pgfmathsetmacro\XDa{10}
\pgfmathsetmacro\YDa{10}
\pgfmathsetmacro\N{40}
\pgfmathsetmacro\k{0.06}
\foreach \n in {1,...,\N}{
\draw (\XA,\YA)--(\XB,\YB)--(\XC,\YC)--(\XD,\YD)--(\XA,\YA);

\pgfmathparse{\XA+\k*(\XB-\XA)}
\let\XAa=\pgfmathresult
\pgfmathparse{\YA+\k*(\YB-\YA)}
\let\YAa=\pgfmathresult
%
\pgfmathparse{\XB+\k*(\XC-\XB)}
\let\XBa=\pgfmathresult
\pgfmathparse{\YB+\k*(\YC-\YB)}
\let\YBa=\pgfmathresult
%
\pgfmathparse{\XC+\k*(\XD-\XC)}
\let\XCa=\pgfmathresult
\pgfmathparse{\YC+\k*(\YD-\YC)}
\let\YCa=\pgfmathresult
\pgfmathparse{\XD+\k*(\XA-\XD)}
\let\XDa=\pgfmathresult
\pgfmathparse{\YD+\k*(\YA-\YD)}
\global\let\YDa=\pgfmathresult
\global\let\XA=\XAa
\global\let\YA=\YAa
\global\let\XB=\XBa
\global\let\YB=\YBa
\global\let\YC=\YCa
\global\let\XC=\XCa
\global\let\XD=\XDa
\global\let\YD=\YDa
};
\node[yshift=-1.5ex] at (5,0) {$N=\N$ et $k=\k$};
\end{tikzpicture}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "../2nd-jpv.tex"
%%% LaTeX-command: "latex -shell-escape"
%%% End: 
