% Title: Demonstration sans parole : carre de la somme = somme des cubes
% Author: Jacques Duma
% Site: http://math.et.info.free.fr/TikZ/index.html

\documentclass{article}

\usepackage{tikz}

\begin{document}

\pagestyle{empty}

\section*{Carr\'e de la Somme = Somme des Cubes}

\vfill

\newcommand{\cube}[3][blue]{\begin{scope}[shift={(#3)}]
\foreach \z in {1,...,#2} \foreach \y in {1,...,#2} \foreach \x in {1,...,#2}
 \shade[ball color=#1!50] (\x-0.5*\y,\z-0.5*\y) circle (0.475);
\end{scope}}

\begin{center}
\begin{tikzpicture} [scale=.9]
\fill [color=blue!50](7,7)rectangle(10,10);
\fill [color=blue!50](3,7)rectangle(6,10);
\fill [color=blue!50](7,3)rectangle(10,6);
\fill [color=blue!50](1,7)rectangle(2,10);
\fill [color=blue!50](7,1)rectangle(10,2);

\fill [color=green!50](4,4)rectangle(6,6);
\fill [color=green!50](1,4)rectangle(3,6);
\fill [color=green!50](4,1)rectangle(6,3);

\fill [color=gray](2,2)rectangle(3,3);
\fill [color=gray](0.9,2)rectangle(1.1,3);
\fill [color=gray](2,0.9)rectangle(3,1.1);

\shade[ball color=blue!50] (1,1) circle (.475);
\foreach \y in {1,2,3} \foreach \x in {2,3}
   \shade[ball color=magenta!50] (\x,\y) circle (.475);
\foreach \y in {2,3} \shade[ball color=magenta!50] (1,\y) circle (.475);
 
\foreach \y in {1,...,6} \foreach \x in {4,5,6}
   \shade[ball color=red!50] (\x,\y) circle (.475);
\foreach \y in {4,5,6} \foreach \x in {1,2,3}
   \shade[ball color=red!50] (\x,\y) circle (.45);
\foreach \y in {1,...,10} \foreach \x in {7,8,9,10}
   \shade[ball color=yellow!50] (\x,\y) circle (.475);
\foreach \y in {7,8,9,10} \foreach \x in {1,...,6}
   \shade[ball color=yellow!50] (\x,\y) circle (.475);
\end{tikzpicture}
\end{center}


{\huge $$(1+2+3+\dots+n)^2=1^3+2^3+3^3+\dots+n^3$$}


\begin{center}
\begin{tikzpicture} [scale=.9]
\cube{1}{0,0}
\cube[magenta]{2}{1.5,0}
\cube[red]{3}{4.5,0}
\cube[yellow]{4}{9,0}
\end{tikzpicture}
\end{center}

\end{document}
