2

I want to generate animated pdf where one image is used as background and animated part which is changed in layer above. Is this possible to do with animate package?

Inspiration: Faraday motor

MNWE:

\documentclass{article}
\usepackage{animate}
\usepackage{tikz} 

\begin{document}
  \begin{animateinline}
    \includegraphics[width=\textwidth]{example-image-a}  % Backgroung image
    \animategraphics[controls,autoplay,loop]{18}{stick_}{0}{59}
  \end{animateinline}
\end{document}
1

1 Answer 1

3

animateinline and \animategraphics cannot be nested.

Use TikZ nodes to align the image parts:

\documentclass[varwidth]{standalone}

\usepackage{tikz}
\usepackage{graphicx}
\usepackage{animate}

\begin{document}
\begin{animateinline}[controls,loop,scale=0.3]{25}
\multiframe{60}{i=0+1}{
  \begin{tikzpicture}[inner sep=0,outer sep=0]
    \node at (0,0) {\includegraphics{down}};
    \ifthenelse{\i<15 \OR \i>45}{
      % stick in front of magnet
      \node at (-2,0.4) {\includegraphics{magnet}};
      \node at (-2,4.05) {\includegraphics{stick-\i}};
    }{
      % stick behind magnet
      \node at (-2,4.05) {\includegraphics{stick-\i}};
      \node at (-2,0.4) {\includegraphics{magnet}};
    }
  \end{tikzpicture}
}
\end{animateinline}\\[1ex]
\small Images: \textcopyright\ National High Magnetic Field Laboratory
\end{document}


The images of the original example were downloaded and renamed with this shell script:

#!/bin/bash
for i in {0..59}
do
    wget https://nationalmaglab.org/html5/MagLabU/source/faradaymotor/images/stickFrames/stick%20\($i\).png
    mv stick\ \($i\).png stick-$i.png
done
wget https://nationalmaglab.org/html5/MagLabU/source/faradaymotor/images/down.png
wget https://nationalmaglab.org/html5/MagLabU/source/faradaymotor/images/magnet.png
3
  • 1
    +1: This is amazing! In addition, I was not aware that an animated version of SVG exists. Commented Feb 19, 2022 at 20:09
  • Can you point me to where I can find this project on your profile (gitlab.com/agrahn)? Commented Feb 19, 2022 at 20:21
  • 1
    I uploaded only the SVG to my GitHub repo. If you want to produce it yourself, just add dvisvgm to the class options: \documentclass[varwidth,dvisvgm]{standalone}. First, you need the images; download them with the commands in the code box at the bottom of my answer. Then run dvilualatex twice and finally dvisvgm --zoom=-1 --bbox=papersize --font-format=woff2 on the DVI file.
    – AlexG
    Commented Feb 19, 2022 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .