1

Consider the following code (taken from http://pstricks.blogspot.dk/2014/06/des-roues-pour-des-routes-au-profil.html):

\documentclass{article}

\usepackage[
  a4paper,
  margin = 2cm
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pstricks-add}
\usepackage{animate}


\pstheader{Road-Wheels.pro}
\definecolor{DOrange}{rgb}{1,0.4,0.2}
\SpecialCoor
\pagestyle{empty}
\def\SinusoidalWheelRoad#1{
  \pstVerb{/ni #1 def
           /di 1 ni dup mul add sqrt neg def
           /d1 di neg 1 add def
           /ai ni 1 di sub div def
           /ai_ 1 ai div def
           /xP 2 Pi mul 18 div \i\space mul def
           /theta 0 xP {Cos di add 1 exch div neg} 10 Simpson RadtoDeg def
           /theta1 {0 exch {Cos di add 1 exch div neg} 10 Simpson RadtoDeg neg} def
           /xP1 0 def % di neg 1 add 2 sqrt mul 0.5 mul neg def
           /yP1 di neg 1 sub def % xP1 neg def
           /alpha {t theta1} def
  }%
}
\psset{
  arrowscale = 1.3,
  arrowinset = 0.05,
  arrowlength = 1.9,
  labelFontSize = \scriptstyle
}
\def\Wheel#1{%
  \pstVerb{/Hh 0 def /Hs 1 def /Hb 1 def /color {Hh Hs Hb} def /dH 1 #1\space div def}
  \definecolor[ps]{macouleur}{hsb}{color}
  \multido{\i = 0+2, \n = 0.1+0.05}{#1}{%
    \pscustom[
      linecolor = black,
      fillstyle = solid,
      fillcolor = macouleur,
      opacity = 0.5
    ]{
      \psplot[
        algebraic,
        plotstyle = curve,
        polarplot = true
      ]{\i\space Pi mul #1\space div Pi 2 div sub}%
       {\i\space 2 add Pi mul #1\space div Pi 2 div sub}%
       {-cos(2*atg(ai*tan((x/2+Pi/4)*ni)))-di}
      \lineto(0,0)
      \closepath%
    }
    \pstVerb{/Hh Hh dH add def}%
  }%
}


\begin{document}

\begin{center}
\psset{
  dimen = middle,
  unit = 0.3
}
\def\nImages{120}% images
\multido{\i = 0+1}{\nImages}{%
\begin{pspicture}(-8,-9)(48,9)
  \psframe(-8,-8.9)(48,8.9)
  \SinusoidalWheelRoad{6}
  \psaxes[
    labelFontSize = \scriptscriptstyle
  ]{->}(0,0)(-6,-8)(47,8)[$x$,90][$y$,0]
  \rput{!theta neg}(!xP 0){%
    \Wheel6
    \psdot[linecolor = red](0,0)
    \psdot[linecolor = DOrange](!xP1 yP1)%
  }
  \pscustom[
    fillstyle = solid,
    fillcolor = yellow!50,
    linecolor = blue,
    opacity = 0.5
  ]{%
  \psplot[
    algebraic,
    plotstyle = curve,
    plotpoints = 720
  ]{-2 Pi mul}{2.5 Pi mul ni mul}{cos(x)+di}
  \psline(*{2.5 Pi mul ni mul} {cos(x)+di})%
         (!2.5 Pi mul ni mul di 2 sub)%
         (!-2 Pi mul di 2 sub)%
         (*{-2 Pi mul} {cos(x)+di})%
  }
  \parametricplot[
    linecolor = DOrange,
    linejoin = 1,
    plotpoints = 720
  ]{0}{xP}{%
    xP1 alpha cos mul yP1 alpha sin mul sub t add
    xP1 alpha sin mul yP1 alpha cos mul add
  }
\end{pspicture}
\newpage%
}

\multido{\i = \nImages+-1}{\nImages}{%
\begin{pspicture}(-8,-9)(48,9)
  \psframe(-8,-8.9)(48,8.9)
  \SinusoidalWheelRoad{6}
  \psaxes[
    labelFontSize = \scriptscriptstyle
  ]{->}(0,0)(-6,-8)(47,8)[$x$,90][$y$,0]
  \rput{!theta neg}(!xP 0){%
    \Wheel6
    \psdot[linecolor = red](0,0)
    \psdot[linecolor = DOrange](! xP1 yP1)%
  }
  \pscustom[
    fillstyle = solid,
    fillcolor = yellow!50,
    linecolor = blue,
    opacity = 0.5
  ]{%
  \psplot[
    algebraic,
    plotstyle = curve,
    plotpoints = 720
  ]{-2 Pi mul}{2.5 Pi mul ni mul}{cos(x)+di}
  \psline(*{2.5 Pi mul ni mul} {cos(x)+di})%
         (!2.5 Pi mul ni mul di 2 sub)%
         (!-2 Pi mul di 2 sub)%
         (*{-2 Pi mul} {cos(x)+di})%
  }
  \parametricplot[
    linecolor = DOrange,
    linejoin = 1,
    plotpoints = 720
  ]{0}{xP}{%
    xP1 alpha cos mul yP1 alpha sin mul sub t add
    xP1 alpha sin mul yP1 alpha cos mul add
  }
\end{pspicture}
\newpage%
}
\end{center}

\end{document}

(The Road-Wheels.pro file can be found here.)

How do I use the animate package to create an animation of all the pictures genereated by the code instead og having a lot of single pictures?

(I would really like to see the correct implementation since I have tried myself for quite some time without success.)

  • \SpecialCoor is implicitly already activated by default so nobody has to explicitly invoke it again. – kiss my armpit Jul 8 '14 at 17:26
3

Just place the first \multido cycle into an animateinline environment, replace

\multido{\i = \nImages+-1}{\nImages}{%

by

\multiframe{\nImages}{i=\nImages+-1}{%

and remove \newpage from the loop body. Then latex, dvips, ps2pdf:

\documentclass{article}

\usepackage[
  a4paper,
  margin = 2cm
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pstricks-add}
\usepackage{animate}


\pstheader{Road-Wheels.pro}
\definecolor{DOrange}{rgb}{1,0.4,0.2}
\SpecialCoor
\pagestyle{empty}
\def\SinusoidalWheelRoad#1{
  \pstVerb{/ni #1 def
           /di 1 ni dup mul add sqrt neg def
           /d1 di neg 1 add def
           /ai ni 1 di sub div def
           /ai_ 1 ai div def
           /xP 2 Pi mul 18 div \i\space mul def
           /theta 0 xP {Cos di add 1 exch div neg} 10 Simpson RadtoDeg def
           /theta1 {0 exch {Cos di add 1 exch div neg} 10 Simpson RadtoDeg neg} def
           /xP1 0 def % di neg 1 add 2 sqrt mul 0.5 mul neg def
           /yP1 di neg 1 sub def % xP1 neg def
           /alpha {t theta1} def
  }%
}
\psset{
  arrowscale = 1.3,
  arrowinset = 0.05,
  arrowlength = 1.9,
  labelFontSize = \scriptstyle
}
\def\Wheel#1{%
  \pstVerb{/Hh 0 def /Hs 1 def /Hb 1 def /color {Hh Hs Hb} def /dH 1 #1\space div def}
  \definecolor[ps]{macouleur}{hsb}{color}
  \multido{\i = 0+2, \n = 0.1+0.05}{#1}{%
    \pscustom[
      linecolor = black,
      fillstyle = solid,
      fillcolor = macouleur,
      opacity = 0.5
    ]{
      \psplot[
        algebraic,
        plotstyle = curve,
        polarplot = true
      ]{\i\space Pi mul #1\space div Pi 2 div sub}%
       {\i\space 2 add Pi mul #1\space div Pi 2 div sub}%
       {-cos(2*atg(ai*tan((x/2+Pi/4)*ni)))-di}
      \lineto(0,0)
      \closepath%
    }
    \pstVerb{/Hh Hh dH add def}%
  }%
}

\begin{document}

\begin{center}
\psset{
  dimen = middle,
  unit = 0.3
}
\def\nImages{120}% images

\begin{animateinline}[
    controls,palindrome
  ]{12}
  \multiframe{\nImages}{i=0+1}{%
  \begin{pspicture}(-8,-9)(48,9)
    \psframe(-8,-8.9)(48,8.9)
    \SinusoidalWheelRoad{6}
    \psaxes[
      labelFontSize = \scriptscriptstyle
    ]{->}(0,0)(-6,-8)(47,8)[$x$,90][$y$,0]
    \rput{!theta neg}(!xP 0){%
      \Wheel6
      \psdot[linecolor = red](0,0)
      \psdot[linecolor = DOrange](!xP1 yP1)%
    }
    \pscustom[
      fillstyle = solid,
      fillcolor = yellow!50,
      linecolor = blue,
      opacity = 0.5
    ]{%
    \psplot[
      algebraic,
      plotstyle = curve,
      plotpoints = 720
    ]{-2 Pi mul}{2.5 Pi mul ni mul}{cos(x)+di}
    \psline(*{2.5 Pi mul ni mul} {cos(x)+di})%
           (!2.5 Pi mul ni mul di 2 sub)%
           (!-2 Pi mul di 2 sub)%
           (*{-2 Pi mul} {cos(x)+di})%
    }
    \parametricplot[
      linecolor = DOrange,
      linejoin = 1,
      plotpoints = 720
    ]{0}{xP}{%
      xP1 alpha cos mul yP1 alpha sin mul sub t add
      xP1 alpha sin mul yP1 alpha cos mul add
    }
  \end{pspicture}
  }
\end{animateinline}
\end{center}

\end{document}
  • @Svend Think of \multiframe as \multido with embedded \newframe. – AlexG Jul 7 '14 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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