3

I recently played around with the animate package. For a different question I created an animation of bouncing balls like this one.

\documentclass{article}

\usepackage{pgfmath}
\usepackage{animate}

\def\bounce#1#2{%
  \pgfmathparse{ 3ex * abs(cos( (#2) / (#1) * 180 )) }%
  \raisebox{\pgfmathresult pt}{\(\circ\)}%
}

\begin{document}

Here are some bouncing circles:
\begin{animateinline}[loop]{24}%
  \multiframe{144}{r=0+0.0417}{% We need 6*24 = 144 frames here.
    \bounce{1}\r%
    \bounce{2}\r%
    \bounce{3}\r%
  }%
\end{animateinline}

\end{document}

To my surprise, the balls (i.e. circles; the glyph created by \(\circ\)) are being distorted at different points during the animation. Here is a screenshot of one frame. MWE output This happens both in Adobe Acrobat Reader DC and PDF XChange Editor.

Why does this happen? How can it be prevented?

schtandard
  • 14,892

1 Answers1

6

You have to make sure that all animation frames have the same vertical and horizontal dimensions. While viewing the animation, the PDF viewer scales the frames to fit into the animation widget which has the first frame's dimensions.

Use the optional arguments for height and depth to ensure that all TeX boxes that are output by \raisebox have the same vertical size

\raisebox{<raiselen>}[<height>][<depth>]{...}

as in the following example:

\documentclass{standalone}

\usepackage{pgfmath} 
\usepackage{animate} 

\def\bounce#1#2{% 
  \pgfmathparse{ 3ex * abs(cos( (#2) / (#1) * 180 )) }%
  \raisebox{\pgfmathresult pt}[4.2ex][0ex]{\(\circ\)}% 
} 

\begin{document} 

\begin{animateinline}[loop,controls,scale=10]{24}% 
  \multiframe{144}{r=0+0.0417}{% We need 6*24 = 144 frames here. 
    \bounce{1}\r% 
    \bounce{2}\r% 
    \bounce{3}\r% 
  }% 
\end{animateinline} 

\end{document}

enter image description here

schtandard
  • 14,892
AlexG
  • 54,894