我发现这个有趣的问题 使用 TikZ 绘制封闭的液滴形曲线 对此,用户垃圾收集器提供了一个更有趣的答案。
只是为了好玩,我尝试在我的系统上编译他的答案,并将其粘贴在这里:
\documentclass[pstricks,border=3pt]{standalone}
\usepackage{pstricks-add}
\def\N{15}
\begin{document}
\psLoop{20}{%
\begin{pspicture}[showgrid=false](-2,-2)(2,5)
\psclip{\psbezier[linestyle=none](0,5)(-6.8,-4.3)(6.8,-4.3)(0,5)}
\psLoop{\N}{
\rput(!rand 21 mod 10 div 1 sub rand 51 mod 10 div 1 sub){$+$}
\rput(!rand 21 mod 10 div 1 sub rand 51 mod 10 div 1 sub){$-$}}%
\endpsclip
\psbezier[linecolor=orange](0,5)(-6.8,-4.3)(6.8,-4.3)(0,5)
\end{pspicture}}
\end{document}
我收到了 120 条错误消息,全部内容如下:13: Undefined control sequence \end{pspicture}}
。有人能解释一下这个问题吗?
答案1
尝试以下在后台编译 PSTricks 代码的代码。您只需要pdflatex -shell-escape main
在终端或 DOS 命令窗口中输入即可。
在该输入文件所在的目录中,您将获得 GIF 动画、PDF 动画、PNG 帧。确保您已安装 ImageMagick(建议使用最新版本以确保该remove
选项可用)。
% this filename is main.tex
% compile it with "pdflatex -shell-escape main" (without the quotes)
\documentclass[preview,border={7pt 0pt 7pt 0pt}]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{WaterDrop.tex}
\documentclass[pstricks,border=3pt]{standalone}
\usepackage{pstricks-add}
\def\N{15}
\begin{document}
\psLoop{20}{%
\begin{pspicture}[showgrid=false](-2,-2)(2,5)
\psclip{\psbezier[linestyle=none](0,5)(-6.8,-4.3)(6.8,-4.3)(0,5)}
\psLoop{\N}{
\rput(!rand 21 mod 10 div 1 sub rand 51 mod 10 div 1 sub){$+$}
\rput(!rand 21 mod 10 div 1 sub rand 51 mod 10 div 1 sub){$-$}}%
\endpsclip
\psbezier[linecolor=orange](0,5)(-6.8,-4.3)(6.8,-4.3)(0,5)
\end{pspicture}}
\end{document}
\end{filecontents*}
\immediate\write18{latex WaterDrop}
\immediate\write18{dvips WaterDrop}
\immediate\write18{ps2pdf WaterDrop.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.
% cmd /c del WaterDrop.ext is Windows command, adapt it to other OS.
\makeatletter
\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del WaterDrop.\x}}
\makeatother
% convert to GIF animation
\immediate\write18{convert -delay 100 -loop 0 -density 200 -alpha remove WaterDrop.pdf WaterDrop.gif}
% convert to PNG
\makeatletter
\immediate\write18{convert -density 200 -alpha on WaterDrop.pdf WaterDrop-\@percentchar02d.png}
\makeatother
\usepackage{animate}
\begin{document}
%\animategraphics[controls,autoplay,loop,scale=<integer>]{<frame rate>}{<PDF filename without extension>}{<left blank>}{<left blank>}
\animategraphics[controls,autoplay,loop,scale=1]{3}{WaterDrop}{}{}
\end{document}