Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a figure, in *.eps, say a pentagon which is already drawn and then included in TeX, and I want to achieve a rotating animation. So the polygon will be rotating about some point (usually its center) at some rate. How is this done?

share|improve this question
    
I'm not sure if latex supports animation. Someone who knows better than I will probably come along soon to confirm or deny. I suspect you may have to make a gif and include that as in this post: tex.stackexchange.com/a/10381/14100 –  Scott H. May 10 '12 at 3:19
add comment

3 Answers

up vote 9 down vote accepted

The topic poster seems to want a single graphic file to be rotated around its centre. In that case, animateinline environment may be the better choice, as the image file is included only once (at least in case of pdfLaTeX/XeLaTeX/dvipdfmx), which saves file size.

\documentclass{article}
\usepackage{animate}
\usepackage{graphicx}

\newlength\imgwd
\setlength\imgwd{2in}
\newlength\imght
\setlength\imght{2in}
\newlength\imgdiag
\setlength\imgdiag{1.4142\imgwd} %should be set to sqrt(imgwd^2+imght^2)

\begin{document}

\begin{animateinline}[controls,loop]{12}
\multiframe{36}{iAng=0+10}{%
  \makebox[\imgdiag][c]{%
    \rule[-0.5\imgdiag]{0pt}{\imgdiag}%
    \rotatebox[origin=c]{\iAng}{%
      \raisebox{-0.5\height}{%
        \includegraphics[width=\imgwd,height=\imght]{tiger}%
      }%
    }%
  }%
}
\end{animateinline}

\end{document}

enter image description here

share|improve this answer
add comment

Here a simple example. I created a list of figures. In your case, if you have a defined picture, you can make a rotation with a \foreach to get the same thing.

animateinline environment is a fine alternativ in AlexG'answer

Update

Step one : Create the pentagon

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\node  [draw,regular polygon, regular polygon sides=5, minimum size=4cm,outer sep=0pt] {};
\end{tikzpicture}
\end{document} 

Step two : the list of pictures in pentagon.pdf with pentagon.tex

\documentclass{beamer} 
\usepackage{tikz} 

\usepackage[active,floats,tightpage]{preview} 
\PreviewEnvironment{tikzpicture} 
\setlength\PreviewBorder{5pt}% 
\begin{document} 
\foreach \a in {0,5,...,360}{% 
   \begin{tikzpicture}
    \clip (-3,-3) rectangle (3,3) ;
    \node[rotate=\a,transform shape] {\includegraphics[width=4cm]{aPentagon}};
 \end{tikzpicture}}
\end{document}

Step three : the final pdf with animate

\documentclass{beamer} 
\usepackage{animate} 
\begin{document} 

\begin{frame}
\begin{center} 
\animategraphics[palindrome]{12}{pentagon}{}{} 
\end{center} 
\end{frame}

\end{document}  

I try animateinline with success to avoid the last two steps but I don't know the options to get a fine result.

The problem here is to get an animated gif because the pdf seems to be wrong.


First try

Step 1

You create a list of pictures. I used beamer and I have a correct size for the pictures. I named triangle.tex the source

\documentclass{beamer} 
\usepackage{tikz} 
\usetikzlibrary{calc}
\usepackage{verbatim} 
\usepackage[active,floats,tightpage]{preview} 
\PreviewEnvironment{tikzpicture} 
\setlength\PreviewBorder{5pt}% 
\begin{document} 

  \newcommand\setC{%
   \pgfmathsetmacro\Cx{5-3*cos(\alpha)}
   \pgfmathsetmacro\Cy{3*sin(\alpha)}
   \fill [blue] (\Cx,\Cy) circle (2pt);
   }%

\foreach \a in {0,10,...,180}{% 
   \begin{tikzpicture} 
    \draw (-1,-1) rectangle (9,5);
    \fill[blue] (0,0) circle (2pt);
    \fill[blue] (4,0) circle (2pt);
    \setC
    \draw (0,0)--(4,0)--(\Cx,\Cy)--cycle;
  \end{tikzpicture} 
 }

\end{document} 

Step 2

I created a new little file animated_triangle.tex. The important line is

 \animategraphics[palindrome]{12}{triangle}{}{} 

palindrome is an option of the animate package (see the doc), 12 number of frames per second (I think ...), triangle is the name of the pdf with the list of pictures. The last two arguments are for the first picture of the animation and the last. Here I use all the pictures.

\documentclass{beamer} 
\usepackage{animate} 
\begin{document} 

\begin{frame}
\frametitle{Produit Scalaire} 
\begin{center} 
\animategraphics[palindrome]{12}{tranim}{}{} 
\end{center} 
\end{frame}

\end{document} 

I don't know how to place an animated gif on tex.se, I placed the pdf . With the help of Peter and the explanations of Martin, I get an animated gif but there are some little problems. A first result is :

enter image description here

share|improve this answer
    
I don't know how to create an animate gif. I saw some examples on the tex.se. If someone can replace my pdf file with an animated gif, I will be happy ! –  Alain Matthes May 10 '12 at 6:45
    
Have a look at the link in my answer to the Sieve of Eratosthenes to an Answer Martin Scharrer provided which uses pdfcrop and ImageMagick's convert to generates a gif –  Peter Grill May 10 '12 at 8:30
    
@PeterGrill Thanks Peter for the link ! –  Alain Matthes May 10 '12 at 9:17
    
Why did you use a two-step method instead of directly putting the parametric tikzpicture into a \multiframe command inside an animateinline environment? –  AlexG May 10 '12 at 10:09
    
I don't know the animateinline environmentand I always made like this but I need to look at your example. It's very possible that your method is better –  Alain Matthes May 10 '12 at 10:14
show 2 more comments

The animate package allows you to do this by supplying a number of images with some base name. The default format is:

\animategraphics[<options>]{<frame rate>}{<base filename>}{<start>}{<finish>}

There are some examples of animations in TeX using TikZ on TeXample.net.

share|improve this answer
    
I have to open the output pdf in Acrobat to see the animation in a Mac. It does not work under preview. People who use Macs do not like this. Therefore, I usually do not include movies and animations. Is there a way around this? –  Sony May 10 '12 at 10:48
    
I have had quite a bit of trouble using animated graphics or much of any interactivity, which apparently uses JavaScript, on anything other than Adobe on PC or Mac. Even Adobe Reader version for tablets does not work for such cases. –  Maesumi Jan 4 '13 at 23:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.