PSTricks 代码动画

PSTricks 代码动画

考虑以下代码(取自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}

(该Road-Wheels.pro文件可以在这里

如何使用animate包来创建由代码生成的所有图片的动画,而不是拥有大量单张图片?

(我真的很想看到正确的实现,因为我自己已经尝试了很长时间都没有成功。)

答案1

只需将第一个\multido循环放入animateinline环境中,替换

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

经过

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

\newpage从循环体中移除。然后latexdvipsps2pdf

\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}

相关内容