骑士之旅动画

骑士之旅动画

在此处输入图片描述

是否可以创建上述动画?我从 Numberphile 中获取了此内容。

答案1

http://asymptote.ualberta.ca/

usepackage("skak");
unitsize(1cm);
void chessboard(int n=3, pen color1= currentpen, pen color2= white)
{
  for (int i=0; i < n; ++i){
    for (int j=0; j < n; ++j){
      fill(shift(j,i)*unitsquare, (i%2 ==0 && j%2 == 0) ? color1 : color2);
      if (i%2 !=0 && j%2 != 0) { fill(shift(j,i)*unitsquare, color1); }
    }
  }
}
chessboard(8,darkgreen,white);
pair pos(pair A){ return (A+(A-(1,1)))/2; }
path[] Lpath=texpath("$\BlackKnightOnWhite$");
picture pic;
filldraw(pic,Lpath,white,black+0.3bp);
add(scale(1.5)*pic,pos((3,5)));
pair[] Pos={(8,8),(7,6),(6,8),(8,7),(7,5),(5,6),(4,8),(2,7),(1,5),(3,6),(2,8),(1,6)};
pair[] listofpostions;
for( pair A : Pos){ listofpostions.push(pos(A));}
draw(operator -- (... listofpostions),red+1.5bp);
for (int i=0; i < listofpostions.length ; ++i)
{
  label(scale(2)*Label("$"+ (string) (i+1) +"$",gray),listofpostions[i]);
}

在此处输入图片描述

import animate;
usepackage("skak");
settings.tex="pdflatex"; 
settings.outformat="pdf"; 

animation Ani;

unitsize(1cm);
void chessboard(int n=3, pen color1= currentpen, pen color2= white)
{
  for (int i=0; i < n; ++i){
    for (int j=0; j < n; ++j){
      fill(shift(j,i)*unitsquare, (i%2 ==0 && j%2 == 0) ? color1 : color2);
      if (i%2 !=0 && j%2 != 0) { fill(shift(j,i)*unitsquare, color1); }
    }
  }
}
chessboard(8,darkgreen,white);

pair pos(pair A){ return (A+(A-(1,1)))/2; }
pair[] Pos={(8,8),(7,6),(6,8),(8,7),(7,5),(5,6),(4,8),(2,7),(1,5),(3,6),(2,8),(1,6)};
pair[] listofpostions;
for( pair A : Pos){ listofpostions.push(pos(A));}

path[] Lpath=texpath("$\BlackKnightOnWhite$");
picture pic;
filldraw(pic,Lpath,white,black+0.3bp);
guide g;
for (int i=0; i < listofpostions.length ; ++i){
save();
g=g--listofpostions[i];
draw(g,(i != 0) ? red+1.5bp : invisible);
add(scale(1.5)*pic,listofpostions[i]);
Ani.add();
restore();
label(scale(2)*Label("$"+ (string) (i+1) +"$",gray),listofpostions[i]);
}
erase();
chessboard(8,darkgreen,white);
draw(g,red+1.5bp);
for (int i=0; i < listofpostions.length ; ++i){
label(scale(2)*Label("$"+ (string) (i+1) +"$",gray),listofpostions[i]);
}
add(scale(1.5)*pic,pos((3,5)));
Ani.add();
erase();
Ani.movie();

在此处输入图片描述

答案2

PSTricks 解决方案仅用于娱乐目的!

它是用从此解决方案

在此处输入图片描述

\documentclass[pstricks,border=\dimexpr355pt/113\relax,12pt]{standalone}
\usepackage{tikzducks}

\newcommand\obj{\rput(.5,.5){\tikz[scale=.35]\duck;}}

\begin{document}
\let\CUMULATIVE\undefined
\foreach \k in {0/0,2/3,4/4,3/6,1/7,2/5,3/3,2/1}{
  \xdef\CUMULATIVE{\ifdefined\CUMULATIVE \CUMULATIVE,\fi \k}
  \begin{pspicture}(8,8)
    \psframe[dimen=i,linewidth=\dimexpr355pt/113\relax,linecolor=brown](8,8)
    \multips(0,0)(0,2){4}{%
      \multips(0,0)(2,0){4}{%
        \multips(0,0)(1,1){2}{\psframe*(1,1)}}}    
        \pscustom[linecolor=red,linewidth=3pt,linejoin=1]{%
            \moveto(.5,.5)%
            \foreach \i/\j in \CUMULATIVE {\lineto(!\i\space .5 add \j\space .5 add)}}
        \foreach \i/\j in \CUMULATIVE {\rput(\i,\j){\obj}}
  \end{pspicture}}
\end{document}

相关内容