Wednesday, 12 November 2014

gif image in beamer presentation

I wish to display some animations in my beamer presentation. The most trivial way that comes to my mind is to use a gif image. How can I put it in the presentation and what should I use to display it? Is there any other way of doing it?
shareimprove this question

    
You could have a look into the beameruserguide Chapter 14, which describes some different methods to do animated stuff. –  Benedikt Bauer Sep 25 '12 at 16:38
    
Does using \includegraphics{<file-name.gif>} not work? –  Peter Grill Sep 25 '12 at 16:46
    
@PeterGrill: GIF is not supported. –  Who is crazy first Sep 25 '12 at 16:58
    
@garbagecollector: useful to mention the context, here -- when pdftex was being developed, gif format was encumbered with a software patent that applied to its compression method (lzw). there are several free software projects that avoided gif, in that context, and pdftex was one of them. it's a pity, since (as sthiadhi says) motion gif is one of the easiest motion formats to handle. –  wasteofspace Sep 25 '12 at 20:21
    
@wasteofspace: Even if gif were supported by pdfTeX, the viewer application would have to support it as well, in particular its animation feature. Only gif creation software using LZW was subject to licensing, not viewing software. Even though, Adobe abstained from supporting animated gif in Acrobat. Perhaps they considered it dispensable. –  AlexG Sep 26 '12 at 7:10

2 Answers

In a single run you will get 4 separate files as follows,
  • a GIF animation
  • a PDF animation
  • a MP4 video
  • a slide that contains a PDF animation and imports a MP4 video as shown in the figure below
enter image description here

Requirements

  • ImageMagick must be installed and its path must be registered to PATH system variable.
  • FFMPEG must be installed and its path must be registered to PATH system variable.

How to compile

The following input file, named as main.tex, must be compiled with pdflatex -shell-escape main. WARNING: If your OS is not Windows, then please adapt the Windows shell command to your OS shell command.
% this filename is main.tex
% compile it with "pdflatex -shell-escape main" (without the quotes)

\documentclass[mathserif]{beamer}

\usepackage{filecontents}

% Create a PDF file that consist of some pages
\begin{filecontents*}{frames.tex}
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\begin{document}
\multido{\i=5+5}{72}
{
    \begin{pspicture}[showgrid=false](-2,-2)(2,2)
        \psparametricplot[algebraic,plotpoints=1000,linecolor=red]{0}{\i}{2*sin(7*t*Pi/180)|2*cos(11*t*Pi/180)}
    \end{pspicture}
}
\end{document}
\end{filecontents*}

\immediate\write18{latex frames}
\immediate\write18{dvips frames}
\immediate\write18{ps2pdf frames.ps}
% sometimes you need to disable auto rotate in ps2pdf. Please follow up if you really need it!
% delete auxiliary files generated by the 3 commands above.
\makeatletter
\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del frames.\x}}
\makeatother

% convert to GIF animation
\immediate\write18{convert -delay 5 -loop 0 -density 75 -alpha remove frames.pdf Lissajous.gif}

% convert to MP4
\makeatletter
\immediate\write18{convert -density 600 -alpha remove frames.pdf frames-\@percentchar04d.png}
\immediate\write18{cmd /c if exist Lissajous.mp4 del Lissajous.mp4}
\immediate\write18{ffmpeg -r 5 -i frames-\@percentchar04d.png -vcodec libx264 Lissajous.mp4}
\immediate\write18{cmd /c if exist frames-*.png del frames-*.png}
\makeatother

% convert to a single PDF animation
\begin{filecontents*}{Lissajous.tex}
\documentclass[preview,border=12pt]{standalone}
\usepackage{animate}
\begin{document}
\animategraphics[controls,loop,autoplay,scale=1]{10}{frames}{}{}
\end{document}
\end{filecontents*}

\immediate\write18{pdflatex Lissajous}
% delete auxiliary files generated by the above command.
\makeatletter
\@for\x:={tex,log,aux}\do{\immediate\write18{cmd /c del Lissajous.\x}}
\makeatother


\usepackage{animate,media9}
\begin{document}

\begin{frame}[t]{Lissajous in action}
\begin{columns}[T]
%=============
\begin{column}{0.5\textwidth}
\begin{block}{PDF Animation}
%\animategraphics[controls,autoplay,loop,scale=<integer>]{<frame rate>}{<PDF filename without extension>}{<left blank>}{<left blank>}
\animategraphics[controls,autoplay,loop,scale=1]{10}{frames}{}{}
\end{block}
\end{column}
%=============
\begin{column}{0.5\textwidth}
\begin{block}{MP4}
\includemedia[
    activate=onclick,
    width=\linewidth,height=\linewidth,
    addresource=Lissajous.mp4,
    flashvars={%
        source=Lissajous.mp4%same path as in addresource!
        &autoPlay=true%optional configuration
        &loop=true%variables
    }
]{}{VPlayer.swf}
\end{block}
\end{column}
%=============
\end{columns}
\end{frame}
\end{document}

Notes:

The auxiliary file named frames.pdf must be removed manually because I cannot remove it from within main.tex. If you know how to do this, let me know!
shareimprove this answer

    
    
There is yet another option. You could convert frames.pdf to animated SWF using swftools and embed this one using \includemedia from media9 package. This keeps the vectorial nature of the graphics (as opposed to MP4). –  AlexG Sep 26 '12 at 8:14
    
@AlexG: OK. Thanks. I will update this answer once I am finished trying it. –  Who is crazy first Sep 26 '12 at 8:15
2  
this could also be written into an arara rule :) –  cmhughes Jun 22 '13 at 19:06
    
@cmhughes: Yes it might be rewritten in an arara rule but learning arara will burden us to spend an extra time. –  Who is crazy first Jun 22 '13 at 19:27
the same without using an external file (the pdf is here: http://perce.de/temp/anim0.pdf):
\documentclass[mathserif]{beamer}
\usepackage{pst-plot,animate}
\begin{document}

\begin{frame}[t]{Lissajous in action}
\begin{columns}[T]
\begin{column}{0.5\textwidth}
\begin{animateinline}[%
  width=0.9\linewidth,
  begin={\begin{pspicture}(-2.1,-2.1)(2.1,2.1)},
  end={\end{pspicture}},
  controls, %palindrome, %autoplay
]{3}
\multiframe{72}{iA=50+50,iB=5+5}{
  \psset{algebraic,plotpoints=\iA,linecolor=red}
  \parametricplot{0}{\iB}{2*sin(7*t*Pi/180)|2*cos(11*t*Pi/180)}
}
\end{animateinline}
\end{column}
\begin{column}{0.5\textwidth}
\begin{align}
    x(t)&=2\sin(7t)\\
    y(t)&=2\cos(11t)    
\end{align}
\end{column}
\end{columns}
\end{frame}

\end{document}
enter image description here
shareimprove this answer

    
I downloaded the pdf and viewed it in evince but the animation doesn't work. Do I need any other pdf viewer for this? –  lovespeed Sep 25 '12 at 18:02
    
I suppose that it works only with acrobat –  Herbert Sep 25 '12 at 18:06
    
Apparently, pst-plot has already imported multido. –  Who is crazy first Sep 25 '12 at 18:50
    
I do not need it anyway ... –  Herbert Sep 25 '12 at 18:59
2  
@chepukha: run the example with xelatex. It does not work with pdflatex. If you want to use several images then have a look into the documentation of animate, it has some examples. –  Herbert May 1 '13 at 18:30

PDF with animations and videos

PDF with animations

Including animations in PDF using LaTeX

The Portable Document Format (PDF) is much more than just a substitute for paper. While printable documents are thought of as static, PDF can be dynamic and interactive, see for example these interactivity demos. In fact, since Adobe has acquired Macromedia, some convergence of PDF and Flash might be expected in the future. But if you go through my example on this page, it will be clear that PDF all by itself at this point in time has (almost) all the features a multimedia author could ask for.
The context of this page is the problem of how to prepare scientific/technical documents. If you have looked at my suggestions for doing scientific presentations using Apple's Keynote, you should be convinced by now that LaTeX is an essential ingredient for any computer-based talk with mathematical content.
In particular, I included some links to LaTeX-based PDF presentation tools that can do almost anything that Keynote can do, based on the power of Adobe Reader.
Traditional movies are essentially sequences of resolution-dependent (rasterized) images, with additional information on how fast to play the frames. But PDF is a format that can display both vector and raster graphics, where the big advantage of vector graphics is its resolution-independence. Therefore, movie formats with vector-graphics frames would be a natural choice for embedding into PDF. The most important such format is Flash SWF format. Based on the type of movie, we can then distinguish three distinct solutions:
  1. Traditional bitmap movie formats (Mpeg etc.)
  2. Vector animations (SWF)
  3. PDF-only animations (using scripting)
For all of these cases, LaTeX provides solutions. The first two are addressed by the movie15 package and its successor, media9. The last solution can be achievd by the animate package. We'll not discuss the latter on this page.

Prerequisites

PDF movies can be displayed with Adobe Reader. In case you encounter problems, first make sure you have the most recent version of Adobe Reader. The Preview Application (on Mac) is not an alternative here because it does not handle multimedia plugins and JavaScript.
For Linux users running the latest version of Adobe Reader, the embedded movie will open in a separate window after you click on the "paper clip" attachment icon and agree to open the file.
Also note that you cannot use Linux acroread to display multimedia embedded with the help of this package. In KDE 4, you may be able to use Okular to view PDFs with embedded movies (unfortunately I can't currently test these features on Linux or Windows, only on Mac).
One more warning: we are using advanced features of PDF here, so you also need a recent version (>1.2) of pdflatex. The TeX-Live 2007 (and later) distribution contains movie15, whereas the tetex distribution doesn't. That's why you should no longer be using texlive.
To create MPEG or other formats, here are some tools (for Mac OS X):
  • GraphicConverter can convert a sequence of images into a movie using File > Export Slide Show to Movie
  • Miro Video Converter has many of the most common export file settings pre-defined. I found its Apple Universal mp4 output format works well when embedded in PDF (also works with media9 below).
  • Livid Batch Export Utility lets you convert movies from one format to another, while also changing the compression and size settings.
  • QT amateur is a free movie player for Mac OS X which can export various movie and image file formats (even in batch mode). It requires Quicktime 7 to be installed on your machine.
  • Apple's Quicktime X application lets you comvert to different formats under the Share and FIle > Export...
  • menu items. In particular, exporting to 480p produced .mov files that work with media9, see below.
  • If you are comfortable with command-line UNIX tools, there are the free packages mpeg2vidcodec or mpegencode, available for Mac from fink or MacPorts. The Imagemagick package also has the command convert which on my platform allows conversion to mpgeg (by automatically calling one of the programs mentioned before)..
  • Flash movies work, too, and this opens additional possibilities for interactivity in your PDF document. Flash animations can be exported from Mathematica, among others.
For additional information, see the pages on making movies.

The movie15 and media9 Packages

Although the movie15 package has been declared "obsolete" after the release of media9, I'll start by discussing movie15 because you're more likely to have it installed even if your TeX distribution is a little older. This package allows you to embed different kinds of movies (e.g., mp4, mov or swf) into a PDF document and have them play inside the displayed page, provided that you display the PDF with Adobe Reader. However, for any given movie format you want to appear in the PDF, you have to have an external movie player installed on your system.
This last point is where the newer media9 package differs from movie15: it relies on the fact that recent versions of Adobe Reader have Flash Player built in, so that external players don't need to be installed if you deliver the embedded movie wrapped in a flash "container." Of course, most computers nowadays do have players for a multitude of movie formats installed anyway; that's why I think it's still worth discussing movie15 first.
The examples here are best suited for a small, "bare-bones" presentation without much stylistic overhead. For the media9 approach, scroll down.

Creating the files

For several years, the way I've been putting movies into PDF presentations has been based on direct application of \pdfannot or \pdfmark - commands understood by pdflatex which allow you to write PDF code. The style movie15.sty by Alexander Grahn uses these commands to create a very flexible and user-friendly way to do this without having to leave the LaTeX level. This package is able to use the features of the newest Adobe Reader, including 3D virtual reality interactivity. Here, I'll address only traditional movie playback to keep things simple.
The method is best described by example.
  1. Assume you have the following movie in MPEG or AVI format (I have an mp4 movie on this web page, but other formats also work):
    To try the example below, download this movie file:
    Circle-m-increase3.mp4
    by right-clicking on the file name.

  2. You can see how I embedded the movie into the HTML code of this very page, and now we want to do the exact same thing with a PDF file by using pdflatex.
    To do this, create a LaTeX file (named, e.g., movie.tex) in the same directory as the movie, containing the following:
    \documentclass[12pt,landscape]{article}
    \usepackage{geometry}
    \geometry{verbose,letterpaper}
    \usepackage{movie15}
    \usepackage{hyperref}
    \begin{document}
    Whispering-gallery mode in a quarter circle:
    \begin{figure}[ht]
    \includemovie[
      poster,
      text={\small(Loading Circle-m-increase3.mp4)}
    ]{6cm}{6cm}{Circle-m-increase3.mp4}
    \end{figure}
    \end{document}
    
    The LaTeX file is downloadable by clicking here. The \includemovie command is the crucial object here. Its last three arguments are the dimensions of the movie and the file name. The dimensions can be chosen arbitrarily and will cause the movie to be rescaled accordingly.
    The commands related to geometry and landscape are not essential; they just turn the output page sideways for on-screen viewing. You should compile this file using the command pdflatex movie.
  3. In order to view the PDF with embedded movie, you need to open movie.pdf with Adobe Reader or Acrobat. The output file can also be downloaded by clicking here. The movie is automatically loaded and represented by its first frame ("poster frame"). Playback starts after you click on the picture and stops on the last frame. I didn't put in any visible movie controls because they appear to be buggy under Windows (thanks to Alexander Grahn for mentioning this). With Mac OS X, controls work fine, so you could add the option controls to \includemovie and obtain the same appearance as on this web page. Even without control buttons, one can always restart the movie by double-clicking on it (this applies to Mac; for Windows, you may just need a single click).
Observe one fascinating detail: The movie itself is contained in the PDF file, instead of having to be shipped as a separate file. In other words, we have created something that deserves the name Portable Document Format. The caveat of course is that the movie (or any other multimedia content for that matter) will only play properly if the PDF viewer manages to find an external program that can read the embedded file format. That is why it is not advisable to use exotic or platform-specific video formats (e.g., .WMV) if you want to send your PDF file to other people.
This dependence on external video players is removed by the media9 package below.

Vector animations

Everything that was said above also applies if the movie you want to include is in Flash SWF format. As mentioned above, the big advantage is that Flash delivers vector animation inside your PDF document. An example file, movie-swf.pdf, shows the result of modifying the \includemovie line in our tex file as follows:
\documentclass[12pt,landscape]{article}
\usepackage{geometry}
\geometry{verbose,letterpaper}
\usepackage{movie15}
\usepackage{hyperref}
\begin{document}
Created by James N{\"o}ckel, January 6, 2008:
\begin{figure}[h!]
\includemovie[
  poster=FlashPoster.jpg,
  text={\Large\bf Click to start\hspace*{400pt}}
]{550pt}{400pt}{blendone.swf}
\end{figure}
\end{document}
This works on OS X provided you have installed the latest update of Adobe Reader (with version 9.1 installed, Adobe Updater provides a fixed version 9.1.2).
Since the poster frame (image shown before the movie is started) can't be found automatically for this Flash animation, I've inserted an image FlashPoster.jpg by hand. As above, you need Adobe Reader to play this movie. Version 8 is required, as is an up-to-date version of Flash Player. The animation blendone.swf was created by James Nöckel, Jan. 06, 2008. Please credit him if you distribute this file in any way!
Speaking of credit for authors of digital media: Adobe has recently announced enhanced digital-rights management capabilities for Flash. Other formats such as Quicktime already offer this, so there isn't really any surprise that Flash wants to offer it, too. The worry may be that Flash movies and games will therefore become less freely available. Looking at some of the Flash games that are out there, this may actually be a good thing... (take this page for example).
But the truth is that giving the author some control over what people do with his or her work should generally be a matter of common sense. It is not in itself a bad development, because authors who want to distribute their work for free can still do so with the same technology. And you wouldn't want to distribute free copies of a file if the author doesn't want you to, right?

Using media9

Since this package is newer, it's again advisable to check whether you have it installed. If you cannot typeset the file below, then your TeX distribution needs some updates. The TeXLive distribution that most people are now using on the Mac lets you do the necessary updates by simply entering the following commands: sudo tlmgr update --self
sudo tlmgr update all
The following example again uses the flash animation blendone.swf with the poster frame FlashPoster.jpg, and the source can be downloaded as media9-swf.tex:
\documentclass{article}
\usepackage{media9}
\usepackage[english]{babel}

\begin{document}
\includemedia[
  activate=onclick,
 width=0.5\textwidth
]{\includegraphics{FlashPoster.jpg}}{blendone.swf}
\end{document}

Another example can be found in this post on mathematica.stackexchange.com, where I use a flash animation created by Mathematica.

Embedding non-flash movies with media9

When I first tried to include the movie Circle-m-increase3.mp4 from the above example with media9, the embedded player was unable to display it. A simple fix for this is to run the movie file through Quicktime Player first: Choose File → Export... and select 480p as the format. If the exported file is called Circle-m-increase3a.move, you can now embed it in your PDF with this source:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{media9}

\begin{document}

\includemedia[
  activate=pageopen,
  width=200pt,height=170pt,
  addresource=Circle-m-increase3a.mov,
  flashvars={%
src=Circle-m-increase3a.mov
&scaleMode=stretch}
]{}{StrobeMediaPlayback.swf}
\end{document}
The ouptut PDF file can be downloaded as autorunmov.pdf.
An alternative is to use `ffmpeg` to create an `mp4` movie that can be recognized by StrobeMediaPlayback. If you don't want to do this from the command line, use Miro Video Converter with the Apple Universal mp4 output format.

noeckel@uoregon.edu
Last modified: Fri Jun 29 07:44:03 PDT 2012

How to convert PSTricks figures as GIF animated pictures?


2 Answers

up vote 26 down vote accepted
Assume that you want to create an animation as follows.
enter image description here

Step 1:

Create a PDF file consists of at lease 2 pages. Compiling the following input file with either latex-dvips-ps2pdf or xelatex produces a PDF file with 30 pages. Each page represent one frame.
% input.tex
\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pstricks-add,fp}

\FPeval{Size}{3.00}
\FPeval{N}{30}
\FPeval{Delta}{round(Size/N:2)}

\begin{document}
\multido{\r=\Size+-\Delta}{\N}
{
    \begin{pspicture}(-\Size,-\Size)(\Size,\Size)
        \psframe*[linecolor=yellow](-\Size,-\Size)(\Size,\Size)
        \pscircle*{\r}
    \end{pspicture}
}
\end{document}
enter image description here

Step 2:

Install ImageMagick.

Step 3:

Convert the PDF to GIF using the following command:
convert -delay <integer> -loop 0 -density <integer> -alpha <on,off,remove> input.pdf output.gif
Remarks:
  • -delay <integer> specifies the delay between 2 consecutive frames in 1/100 second.
  • -density <integer> specifies the resolution.
  • -alpha <on,off,remove> specifies whether or not you enable, disable or remove the alpha channel.
enter image description here

Another example:

enter image description here
\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-coil,pstricks-add}
\usepackage[nomessages]{fp}
\newcommand\const[3][6]{%
    \expandafter\FPeval\csname#2\endcsname{round(#3:#1)}%
    \pstVerb{/#2 \csname#2\endcsname\space def}%
}
\newcommand\Const[3][7]{\begingroup\edef\temp{\endgroup\noexpand\const[#1]{#2}{#3}}\temp}

\Const{CoilArm}{0.250}
\Const{CoilWidth}{0.300}
\Const{CoilTurn}{50/3}
\Const{DeltaY}{0.5}
\Const{Amplitude}{1.5}
\Const{FPS}{25}% frame rate must be synced with the convert's delay!
\Const{Vx}{2}% propagation speed
\Const{Period}{1}% second

\def\Y#1{-\DeltaY-\Amplitude*cos(2*\psPi*#1/\Period)+2}

\psset
{
    coilarm=\CoilArm,
    coilwidth=\CoilWidth,
}


\newcommand\System[4][0]{% #1: box, #2: x, #3: y, #4: label
    \uput[90](#2,4.25){#4}
    \Const{CoilHeight}{(4-(#3)-2*CoilArm)/(CoilWidth*CoilTurn)}
    \pszigzag[coilheight=\CoilHeight,linejoin=2](#2,4)(#2,#3)
    \ifnum#1=1
    \bgroup
        \psset{origin={#2,#3}}
        \psframe[dimen=inner,fillstyle=solid,fillcolor=black](-0.5,0)(0.5,-1)
        \psdot[linecolor=yellow](0,-0.5)
    \egroup
    \fi
}

\Const{DeltaTime}{1/\FPS}
\Const[0]{TotalFrames}{\FPS*\Period}

\begin{document}
\multido{\n=0.000+\DeltaTime}{\TotalFrames}{%
\begin{pspicture*}[showgrid=false](-1.5,-2)(3.5,5)
    \psframe[fillstyle=vlines,hatchsep=2pt,hatchwidth=0.5\pslinewidth,hatchcolor=gray,hatchangle=45](0,4)(2,4.25)
    \Const{Yn}{\Y{\n}}%
    \System[1]{1}{\Yn}{}
    \psplot[algebraic,linecolor=red,plotpoints=1000]{-1.5}{3.5}{\Y{((-\Vx*\n+x-1)/\Vx)}-0.5}
\end{pspicture*}}

\end{document}
Use convert -delay 4 -loop 0 -density 200 -alpha remove shm.pdf shm.gif. The -delay 4 represents the rate of 25 frame per second. The formula is FPS = 100 / DELAY.
shareimprove this answer

1  
OK, you could just say "use Image Magick" =) Thanks! –  Physicsworks Sep 21 '12 at 17:53
4  
"use Image Magick" should be submitted as a comment rather than an answer that I actually want. –  Who is crazy first Sep 22 '12 at 15:49
    
@AdorableCreature,follow your steps, I can't get animated GIF. I only get the first page picture of the 30 pages pdf file in my GIF file. How to solve it? Thanks. –  Pig Cry Jan 7 '13 at 4:23
    
@PigCry: Make sure you had 30 pages in your PDF and you typied the convert command correctly. –  Who is crazy first Jan 7 '13 at 4:44
    
@AdorableCreature: yes, I have 30 pages. The convert command is convert -delay 100 -loop 0 -density 200 -alpha on input.pdf output.gif. –  Pig Cry Jan 7 '13 at 5:13
Just in case you need a PDF animation then use the following template.
% this filename is main.tex
% compile it with pdflatex -shell-escape main

\documentclass[preview]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
% put you compilable PSTricks input file here!
\end{filecontents*}


\usepackage{animate}

\immediate\write18{latex temporary}
\immediate\write18{dvips temporary}
\immediate\write18{ps2pdf temporary.ps}

\begin{document}
\animategraphics[controls,autoplay,loop,scale=1]{<frame rate>}{temporary}{}{}
\end{document}
For example,
% this filename is main.tex
% compile it with pdflatex -shell-escape main

\documentclass[preview]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-coil,pstricks-add}
\usepackage[nomessages]{fp}
\newcommand\const[3][6]{%
    \expandafter\FPeval\csname#2\endcsname{trunc(#3:#1)}%
    \pstVerb{/#2 \csname#2\endcsname\space def}%
}
\newcommand\Const[3][3]{\begingroup\edef\temp{\endgroup\noexpand\const[#1]{#2}{#3}}\temp}

\Const{CoilArm}{0.250}
\Const{CoilWidth}{0.300}
\Const{CoilTurn}{50/3}
\Const{DeltaY}{0.5}
\Const{Amplitude}{1.5}
\Const{FPS}{25}
\Const{Vx}{2}% propagation speed
\Const{Period}{1}% second

\def\Y#1{-\DeltaY-\Amplitude*cos(2*\psPi*#1/\Period)+2}

\psset
{
    coilarm=\CoilArm,
    coilwidth=\CoilWidth,
}


\newcommand\System[4][0]{% #1: box, #2: x, #3: y, #4: label
    \uput[90](#2,4.25){#4}
    \Const{CoilHeight}{(4-(#3)-2*CoilArm)/(CoilWidth*CoilTurn)}
    \pszigzag[coilheight=\CoilHeight,linejoin=2](#2,4)(#2,#3)
    \ifnum#1=1
    \bgroup
        \psset{origin={#2,#3}}
        \psframe[dimen=inner,fillstyle=solid,fillcolor=black](-0.5,0)(0.5,-1)
        \psdot[linecolor=yellow](0,-0.5)
    \egroup
    \fi
}

\Const[3]{DeltaTime}{1/\FPS}
\Const[0]{TotalFrames}{\FPS*\Period}

\begin{document}
\multido{\n=0.000+\DeltaTime}{\TotalFrames}{%
\begin{pspicture*}[showgrid=false](-1.5,-2)(3.5,5)
    \psframe[fillstyle=vlines,hatchsep=2pt,hatchwidth=0.5\pslinewidth,hatchcolor=gray,hatchangle=45](0,4)(2,4.25)
    \Const{Yn}{\Y{\n}}%
    \System[1]{1}{\Yn}{}
    \psplot[algebraic,linecolor=red,plotpoints=1000]{-1.5}{3.5}{\Y{((-\Vx*\n+x-1)/\Vx)}-0.5}
\end{pspicture*}}

\end{document}
\end{filecontents*}


\usepackage{animate}

\immediate\write18{latex temporary}
\immediate\write18{dvips temporary}
\immediate\write18{ps2pdf temporary.ps}

\begin{document}
\animategraphics[controls,autoplay,loop,scale=1]{25}{temporary}{}{}
\end{document}
And compile it with pdflatex -shell-escape main.
shareimprove this answer

    
there is no need to load package fp when it is not really needed \documentclass[pstricks,border=0pt]{standalone} \usepackage{pstricks-add} \makeatletter \def\Size{3} \def\N{30} \def\Delta{\strip@pt\dimexpr \Size pt/\N} \makeatother [...] more animations are here: tug.org/PSTricks/main.cgi?file=Animation/gif/gif –  Herbert Sep 21 '12 at 18:00
    
Thanks for this trick. I put \newcommand\const[3][3]{% \expandafter\FPeval\csname#2\endcsname{round(#3:#1)}% \pstVerb{/#2 \csname#2\endcsname\space def}% } in a package to make my project consistent. –  Who is crazy first Sep 21 '12 at 18:06
    
looks like " why an easy solution when a complicated one is possible ..." ;-) –  Herbert Sep 21 '12 at 18:13