2

I have the following code earlier posted by Alenanno. I want to give an animated proof of quadratic formula. My question is:

  • I want to improve the code so that when I am multiplying with $4a$, then $4a$ and $bx$ comes down from equation no 2 and so on with $4aax^2$ and $4ac.$
  • Then I want $a$ and $\textcolor{red}{a}$ to merge so it becomes $a^2$. How to do it?

\documentclass[tikz, margin=10pt]{standalone}

\newcommand\basicstuff{
    \path (-9,-5) rectangle (9,5);
}

\tikzset{
    bas/.style={text width=6cm}
}

\begin{document}\Huge
\foreach \x in {0,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\end{tikzpicture}
}
%
\foreach \x [
    count=\xx starting from 0, 
    evaluate=\x as \opac using (\x/10),
    evaluate=\x as \y using (3-\x)
    ] in {0,.25,...,2}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas, opacity=\opac] at (0,\y) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

%\node[bas, opacity=\opac] at (3,\y) {$\textcolor{green}{bx}$};
\end{tikzpicture}
}
%
\foreach \x in {1,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};


\end{tikzpicture}
}



%---------------------------


\foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas, opacity=\opac] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm} 
\node[bas, opacity=\opac] at (4.4,0.88) {$)$};
\node[bas, opacity=\opac] at (-1.2,.88) {$4a\cdot$};
\node[bas, opacity=\opac] at (6,.88) {$\cdot4a$};
\end{tikzpicture}
}

%
%


%-------------------------------------------------------------------------------------------------------

\foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm} 
\node[bas] at (4.4,0.88) {$)$};
\node[bas] at (-1.2,.88) {$4a\cdot$};
\node[bas] at (6,.88) {$\cdot4a$};

\node[bas, opacity=\opac] at (-0.9,-1.) {$4a \textcolor{red}{ax^2}  \,$};
\end{tikzpicture}
}
%--------------------------------------------------------------------------------------------------------------------------

\foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm} 
\node[bas] at (4.4,0.88) {$)$};
\node[bas] at (-1.2,.88) {$4a\cdot$};
\node[bas] at (6,.88) {$\cdot4a$};
\node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
\node[bas, opacity=\opac] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
\end{tikzpicture}
}

%--------------------------------------------------


%--------------------------------------------------------------------------------------------------------------------------

\foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm} 
\node[bas] at (4.4,0.88) {$)$};
\node[bas] at (-1.2,.88) {$4a\cdot$};
\node[bas] at (6,.88) {$\cdot4a$};
\node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
\node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
\node[bas, opacity=\opac] at (4.2,-1.2) {$+ \,4a \textcolor{blue}{c}$};
\end{tikzpicture}
}
%-------------------------------------------------------------------------




\foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm} 
\node[bas] at (4.4,0.88) {$)$};
\node[bas] at (-1.2,.88) {$4a\cdot$};
\node[bas] at (6,.88) {$\cdot4a$};
\node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
\node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
\node[bas] at (4.2,-1.2) {$+ \,4a \textcolor{blue}{c}$};

\node[bas, opacity=\opac] at (6.5,-1.2) {$ = 0 $};
\end{tikzpicture}
}



%-------------------------------------------------------------------------



\foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10,10,10,10,9,8,...,0}{
\begin{tikzpicture}
\basicstuff

\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};

\node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm} 
\node[bas] at (4.4,0.88) {$)$};
\node[bas] at (-1.2,.88) {$4a\cdot$};
\node[bas] at (6,.88) {$\cdot4a$};
\node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
\node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
\node[bas] at (4.2,-1.2) {$+ \,4a \textcolor{blue}{c}$};

\node[bas] at (6.5,-1.2) {$ = 0 $};


%\node[bas, opacity=\opac] at  (-0.9,-1.) {$  4 \textcolor{red}{a^2x^2}$};
\end{tikzpicture}
}



\end{document}
user
  • 55
  • I am using code posted by Alenanno. I am not rude at all but I think you should be polite. – user Apr 22 '16 at 21:23
  • Thanks for fixing it. I've added the link. This also helps people who want to look at the original answer or question for further information. – cfr Apr 22 '16 at 21:27
  • I did not know that I should be writing the author's name. Sorry for my mistake. – user Apr 22 '16 at 21:27
  • No problem. I probably overreacted. – cfr Apr 22 '16 at 21:28

1 Answers1

3

For the first question, you can gradually change the distances as you alter the opacity using the same basic idea. At least, I think so. I don't entirely understand why things are lower to the right of the equation i.e. why 4ac is lower than 4abx and that is lower than 4aax^2, so perhaps I've not properly understood how this is meant to work.

\documentclass[border=10pt,tikz,multi]{standalone}
% code from Alenanno's answer at http://tex.stackexchange.com/a/305603/
\newcommand\basicstuff{
  \path (-9,-5) rectangle (9,5);
}
\tikzset{%
  bas/.style={text width=6cm}
}
\begin{document}\Huge
  \foreach \x in {0,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
    \end{tikzpicture}
  }
  \foreach \x [
  count=\xx starting from 0,
  evaluate=\x as \opac using (\x/10),
  evaluate=\x as \y using (3-\x)
  ] in {0,.25,...,2}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas, opacity=\opac] at (0,\y) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      %\node[bas, opacity=\opac] at (3,\y) {$\textcolor{green}{bx}$};
    \end{tikzpicture}
  }
  \foreach \x in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
    \end{tikzpicture}
  }
  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas, opacity=\opac] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas, opacity=\opac] at (4.4,0.88) {$)$};
      \node[bas, opacity=\opac] at (-1.2,.88) {$4a\cdot$};
      \node[bas, opacity=\opac] at (6,.88) {$\cdot4a$};
    \end{tikzpicture}
  }
  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas] at (4.4,0.88) {$)$};
      \node[bas] at (-1.2,.88) {$4a\cdot$};
      \node[bas] at (6,.88) {$\cdot4a$};
      \node[bas, opacity=\opac] at (-0.9,{1-\x/5}) {$4a \textcolor{red}{ax^2}  \,$};
    \end{tikzpicture}
  }
  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas] at (4.4,0.88) {$)$};
      \node[bas] at (-1.2,.88) {$4a\cdot$};
      \node[bas] at (6,.88) {$\cdot4a$};
      \node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
      \node[bas, opacity=\opac] at (1.5,{.9-\x/5}) {$+ \,4a \textcolor{green}{bx}$};
    \end{tikzpicture}
  }
  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas] at (4.4,0.88) {$)$};
      \node[bas] at (-1.2,.88) {$4a\cdot$};
      \node[bas] at (6,.88) {$\cdot4a$};
      \node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
      \node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
      \node[bas, opacity=\opac] at (4.2,{.8-\x/5}) {$+ \,4a \textcolor{blue}{c}$};
    \end{tikzpicture}
  }
  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas] at (4.4,0.88) {$)$};
      \node[bas] at (-1.2,.88) {$4a\cdot$};
      \node[bas] at (6,.88) {$\cdot4a$};
      \node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
      \node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
      \node[bas] at (4.2,-1.2) {$+ \,4a \textcolor{blue}{c}$};
      \node[bas, opacity=\opac] at (6.5,{.8-\x/5}) {$ = 0 $};
    \end{tikzpicture}
  }
  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10,10,10,10,9,8,...,0}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas] at (4.4,0.88) {$)$};
      \node[bas] at (-1.2,.88) {$4a\cdot$};
      \node[bas] at (6,.88) {$\cdot4a$};
      \node[bas] at (-0.9,-1.) {$4a \textcolor{red}{ax^2} $};
      \node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
      \node[bas] at (4.2,-1.2) {$+ \,4a \textcolor{blue}{c}$};
      \node[bas] at (6.5,-1.2) {$ = 0 $};
      %\node[bas, opacity=\opac] at  (-0.9,-1.) {$  4 \textcolor{red}{a^2x^2}$};
    \end{tikzpicture}
  }
\end{document}

For the second question, can't you simply use something like the following?

  \foreach \x[ evaluate=\x as \opac using (\x/10),] in {1,...,10}{
    \begin{tikzpicture}
      \basicstuff
      \node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (0,1) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}=0$};
      \node[bas] at (-0.2,0.88) {$( $}; %\hspace{4.4cm} \right) \hspace {1.cm}
      \node[bas] at (4.4,0.88) {$)$};
      \node[bas] at (-1.2,.88) {$4a\cdot$};
      \node[bas] at (6,.88) {$\cdot4a$};
      \node[bas, opacity={1-\opac}] at (-0.9,-1) {$4a \textcolor{red}{ax^2} $};
      \node[bas] at (1.5,-1.1) {$+ \,4a \textcolor{green}{bx}$};
      \node[bas] at (4.2,-1.2) {$+ \,4a \textcolor{blue}{c}$};
      \node[bas] at (6.5,-1.2) {$ = 0 $};
      \node[bas, opacity=\opac] at  (-0.9,-1) {$  4 \textcolor{red}{a^2x^2}$};
    \end{tikzpicture}
  }

GIF

cfr
  • 198,882
  • It is a long proof for some of my students. If I convert to gif, then it runs too fast for most of my students. Therefore I want to make it in animation so that they can stop whenever they want. How is it possible? – user Apr 23 '16 at 13:53
  • The code doesn't make a GIF. I just did that to post it here. So however you were creating the animation before from the slides, you should be able to create the animation now from the modified slides. The GIF is just for demonstration purposes here where you can't post an ordinary Beamer animation. – cfr Apr 23 '16 at 19:22
  • I don't know why my GIF came out so small. I'm not very good with GIFs, to be honest, as I hardly ever make animations of any kind ;). – cfr Apr 23 '16 at 20:43