Asked
Active
Viewed 338 times
0
-
https://tex.stackexchange.com/questions/5396/is-there-any-way-to-include-an-animated-gif-directly – Henri Menke Apr 21 '16 at 16:40
-
Not exactly. I am not thinking to include it in pdf. I want to make it using latex, tikz. – user Apr 21 '16 at 16:44
-
http://texdoc.net/texmf-dist/doc/generic/pgf/pgfmanual.pdf – Henri Menke Apr 21 '16 at 16:47
-
http://tex.stackexchange.com/a/303506/1952 – Ignasi Apr 21 '16 at 17:01
-
To the downvoter: especially with new users, I think it is wise to leave a comment explaining why you think that this question isn’t a good one. – GuM Apr 21 '16 at 18:05
1 Answers
3
That's a pretty elaborate animation, so here's a start. If you have trouble (and probably you will), feel free to ask a new question, but remember to keep it focused on a specific issue you got stuck with.
Adding tikz to the standalone class options allows your pdf to have one page per frame.
To compile this as a .gif, install imagemagick in your system, then do this in your Terminal/Command Prompt:
convert -delay 10 -loop 0 -density 300 -scale 400 -alpha remove file.pdf file.gif
where file.pdf is the name of your file and file.gif is the name of the resulting .gif file, change the name accordingly.
Output

Code
\documentclass[tikz, margin=10pt]{standalone}
\newcommand\basicstuff{
\path (-5,-3) rectangle (5,3);
}
\tikzset{
bas/.style={text width=4cm}
}
\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}$};
\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}$};
\node[bas, opacity=\opac] at (-\x,\y) {$\textcolor{red}{axx}$};
\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}$};
\node[bas] at (-2,1) {$\textcolor{red}{axx}$};
\end{tikzpicture}
}
%
\foreach \y [
count=\xx starting from 0,
evaluate=\xx as \xi using (-2.75-(.25*-\xx*1.5)),
evaluate=\xx as \yi using (.8-(.25*\xx*2.5)),
evaluate=\y as \x using (1-\y)
] in {1,.8,...,0}{
\begin{tikzpicture}
\basicstuff
\node[bas] at (0,3) {$\textcolor{red}{ax^2} + \textcolor{green}{bx} + \textcolor{blue}{c}$};
\filldraw[draw=red, fill=red!50] (-2.75,.6) rectangle (\xi,\yi);
\path (-2.75,.8) -- (-2.75,\yi) node[left, midway] {$\textcolor{red}{ax}$};
\path (-2.75,.5) -- (\xi,.5) node[above, midway] {$\textcolor{red}{x}$};
\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}$};
\filldraw[draw=red, fill=red!50] (-2.75,.6) rectangle (-.875,-2.325);
\path (-2.75,.8) -- (-2.75,-2.325) node[left, midway] {$\textcolor{red}{ax}$};
\path (-2.75,.5) -- (-.875,.5) node[above, midway] {$\textcolor{red}{x}$};
\end{tikzpicture}
}
\end{document}
Alenanno
- 37,338
-
Thanks a lot you are so helpful :-) Because of you I can make some beautiful animations for my class. – user Apr 21 '16 at 17:38
-
Why gif? I would use the animate package. (But I don't like such animations, I prefer when such explanation don't move so that I can study them at my pace). – Ulrike Fischer Apr 21 '16 at 18:10
-
@UlrikeFischer It depends on the medium I suppose, but I totally see where you're coming from. I think that "animations" as in, animated transactions from one state to another, are nice to see in a presentation when the teacher is explaining. Or for example if the animation is relevant for the topic (i.e. physics class). I find the animate package to be a bit arduous to use. :P – Alenanno Apr 21 '16 at 18:19
-
As you are drawing the pictures with tikz anyway, you only need to insert \newframe at suitable places. – Ulrike Fischer Apr 21 '16 at 18:28
-
How does it work with animation adding \newframe. It might be useful for my student, since gif is too quick for some of them? – user Apr 21 '16 at 18:48
-
@Alenanno : Just want to understand your comment, what does arduous mean; cannot find it in my dict. – AlexG Apr 21 '16 at 19:15
-
-
@Alenanno : Oh, really? Just include your PDF with
\animategraphics[controls]{20}{file}{}{}. – AlexG Apr 21 '16 at 19:26 -
@Alenanno Will you please tell me how have you calculated the following: evaluate=\xx as \xi using (-2.75-(.25-\xx1.5)), evaluate=\xx as \yi using (.8-(.25\xx2.5)), evaluate=\y as \x using (1-\y) ] in {1,.8,...,0}{ – user Apr 22 '16 at 15:39
-
