Assume that you want to create an animation as follows.
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}
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.
Another example:
\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
.
convert
command correctly. – Who is crazy first Jan 7 '13 at 4:44convert
command isconvert -delay 100 -loop 0 -density 200 -alpha on input.pdf output.gif
. – Pig Cry Jan 7 '13 at 5:13