\documentclass[beamer]{standalone}
\usepackage{tikz,graphicx,comment,ifthen,amscd,xcomment,xspace,xparse}
\usetikzlibrary{external}
\tikzexternalize % activate!

\colorlet{mygrey}{black!90}
\colorlet{gris}{black!50}
\colorlet{talert}{red!80!black}
\colorlet{talert2}{white!60!black}
\colorlet{nalert}{blue!50!cyan}
\colorlet{calert}{blue!50!purple}
\colorlet{galert}{green!60!black}
\colorlet{alert}{talert}

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{shapes,trees,patterns,decorations.pathmorphing,
  decorations.pathreplacing,arrows,automata,positioning,calc,fadings}

\tikzset{tilingborder/.style={
    draw,
    decorate,
    decoration={
      random steps,
      segment length=7pt,
      amplitude=4pt
    }
  }}
\begin{document}
\begin{standaloneframe}
\only<1-7>{
  \begin{tikzpicture}[scale=0.2]
    \pgfmathsetseed{1}
    \clip[draw,decorate,decoration={random steps,segment length=7pt,amplitude=4pt}] (12,12) rectangle +(40,40);
    \begin{scope}[shift={(-0.5,0.5)},color=gray]
      % \draw (0,0) grid (64,64);
    \end{scope}
    \only<1>{
      \tikzset{
        lignespaires/.style={line width=2pt,color=talert},
        lignesimpaires/.style={line width=2pt,color=talert}
      }
    }
    \only<2>{
      \tikzset{
        lignespaires/.style={line width=2pt,color=blue},
        lignesimpaires/.style={line width=2pt,color=talert}
      }
    }
    \only<3->{
      \tikzset{
        lignespaires/.style={line width=2pt,color=white},
        lignesimpaires/.style={line width=2pt,color=talert}
      }
    }
    \draw[lignespaires] (0,0) -- (0,64) -- (64,64);
    % Niveau 1
    \foreach \i in {0,...,15}{
      \foreach \j in {0,...,15}{
        \draw[lignesimpaires] (\i*4,\j*4) ++(1,1) rectangle +(2,2);
      }
    }
    % Niveau 2
    \foreach \i in {0,...,7}{
      \foreach \j in {0,...,7}{
        \draw[lignespaires] (\i*8,\j*8) ++(2,2) rectangle +(4,4);
      }
    }
    % Niveau 3
    \foreach \i in {0,...,3}{
      \foreach \j in {0,...,3}{
        \draw[lignesimpaires] (\i*16,\j*16) ++(4,4) rectangle +(8,8);
      }
    }
    % Niveau 4
    \foreach \i in {0,...,1}{
      \foreach \j in {0,...,1}{
        \draw[lignespaires] (\i*32,\j*32) ++(8,8) rectangle +(16,16);
      }
    }
    % Niveau 5
    \foreach \i in {0}{
      \foreach \j in {0}{
        \draw[lignesimpaires] (\i*64,\j*64) ++(16,16) rectangle +(32,32);
      }
    }
    \draw[lignespaires] (32,0) -- (32,32) -- (64,32);
    
    %%%%%%%%%% 
    % Calcul !!!
    %%%%%%%%%% 
    \foreach \i in {0,...,15}{
      \foreach \j in {0,...,15}{
        \only<4>{
          \fill[color=gray] (\i*4,\j*4) ++(1,1) rectangle +(2,2);
          \draw[-latex,decorate,decoration={snake,amplitude=1mm,segment length=1mm,pre length=.5mm,
            post length=1.5mm}] (\i*4,\j*4) ++(2,1) -- +(0,2);
        }
        \draw[lignesimpaires] (\i*4,\j*4) ++(1,1) rectangle +(2,2);
      }
    }
    
    % \foreach \i in {0,...,7}{
    % \foreach \j in {0,...,7}{
    % \only<12>{\fill[color=gray] (\i*8,\j*8) ++(2,2) rectangle +(4,4);}
    % \draw[very thick, color=lignespaires] (\i*8,\j*8) ++(2,2) rectangle +(4,4);
    % }
    % }
    \foreach \i in {0,...,3}{
      \foreach \j in {0,...,3}{
        \only<5>{
          \fill[color=gray] (\i*16,\j*16) ++(4,4) rectangle +(8,8);
          \draw[-latex,decorate,decoration={snake,amplitude=2mm,segment length=5mm,pre length=4mm,
            post length=3mm}] (\i*16,\j*16) ++(8,4) -- +(0,8);
        }
        \draw[lignesimpaires] (\i*16,\j*16) ++(4,4) rectangle +(8,8);
      }
    }
    % \foreach \i in {0,...,1}{
    % \foreach \j in {0,...,1}{
    % \only<13>{\fill[color=gray] (\i*32,\j*32) ++(8,8) rectangle +(16,16);}
    % \draw[very thick, color=lignespaires] (\i*32,\j*32) ++(8,8) rectangle +(16,16);
    % }
    % }
    \foreach \i in {0}{
      \foreach \j in {0}{
        \only<6>{
          \fill[color=gray] (\i*64,\j*64) ++(16,16) rectangle +(32,32);
          \draw[-latex,thick, decorate,decoration={snake,amplitude=16mm,segment length=10mm,pre length=8mm,
            post length=8mm}] (\i*64,\j*64) ++(32,16) -- +(0,32);
        }
        \draw[lignesimpaires] (\i*64,\j*64) ++(16,16) rectangle +(32,32);
      }
    }
    \only<19>{\fill[color=gray] (0,0) rectangle +(64,64);
      \draw[-latex,thick, decorate,decoration={snake,amplitude=20mm,segment length=15mm,pre length=8mm,
        post length=8mm}] (32,0) -- +(0,64);
    }
    % \only<14>{\fill[color=gray] (32,0) rectangle +(32,32);}
  \end{tikzpicture}
}
\end{standaloneframe}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
