hf=figure('name','汉诺塔游戏仿真'); %加标题
axis([0,12,0,12]); %画坐标
set(hf,'color','w'); %填充背景
hold on; %保持图形
axis('off'); %隐藏网络线
rectangle('position',[0,0,12,0.5],'FaceColor',[0,1.0,0]); %画底版
line([3;3],[0.5,8],'color','r','linestyle','-','linewidth',1.5);
line([6;6],[0.5,8],'color','r','linestyle','-','linewidth',1.5);
line([9;9],[0.5,8],'color','r','linestyle','-','linewidth',1.5); %画出三条路线
a=line([3;3],[0.5,1.0],'color','c','linestyle','-','linewidth',65); %画出一号长方体木块
b=line([3;3],[1.0,1.5],'color','b','linestyle','-','linewidth',45);%画出二号长方体木块
c=line([3;3],[1.5,2.0],'color','k','linestyle','-','linewidth',30); %画出三号长方体木块
d=line([3;3],[2.0,2.5],'color','y','linestyle','-','linewidth',25);%画出四号长方体木块
e=line([3;3],[2.5,3.0],'color','m','linestyle','-','linewidth',15);%画出五号长方体木块
%设置五木板的运动
%设置五号长方体木块的运动,竖直向上运动到第一条路线的最上方
t1=2.5; dt=0.05;
while t1<=8
t1=t1+dt;
set(e,'xdata',[3;3],'ydata',[t1;t1+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
%设置五号长方体木块的运动,水平运动到第三条路线的最上方
t2=3; dt=0.05;
while t2<=9
t2=t2+dt;
set(e,'xdata',[t2;t2],'ydata',[t1;t1+0.5]);
drawnow; set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向下运动到第三条路线的下方
t3=8; dt=0.05;
while t3>=0.5
t3=t3-dt;
set(e,'xdata',[9;9],'ydata',[t3;t3+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
%设置四号长方体木块的运动,竖直向上运动到第一条路线的最上方
t4=2.0; dt=0.05;
while t4<=8
t4=t4+dt;
set(d,'xdata',[3;3],'ydata',[t4;t4+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,水平运动到第二条路线的最上方
t5=3; dt=0.05;
while t5<=6
t5=t5+dt;
set(d,'xdata',[t5;t5],'ydata',[t4;t4+0.5]);
drawnow; set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,竖直向下运动到第二条路线的最下方
t6=8; dt=0.05;
while t6>=0.5
t6=t6-dt;
set(d,'xdata',[6;6],'ydata',[t6;t6+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
%设置五号长方体木块的运动,竖直向上运动到第三条路线的最上方
t7=0.5; dt=0.05;
while t7<=8
t7=t7+dt;
set(e,'xdata',[9;9],'ydata',[t7;t7+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,水平运动到第二条路线的最上方
t8=9; dt=0.05;
while t8>=6
t8=t8-dt;
set(e,'xdata',[t8;t8],'ydata',[t7;t7+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向下运动到第二条路线的下方
t9=8; dt=0.05;
while t9>=1.0
t9=t9-dt;
set(e,'xdata',[6;6],'ydata',[t9;t9+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置三号长方体木块的运动,竖直向上运动到第一条路线的上方
t10=1.5; dt=0.05;
while t10<=8
t10=t10+dt;
set(c,'xdata',[3;3],'ydata',[t10;t10+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置三号长方体木块的运动,水平运动到第三条路线的上方
t11=3; dt=0.05;
while t11<=9
t11=t11+dt;
set(c,'xdata',[t11;t11],'ydata',[t10;t10+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置三号长方体木块的运动,竖直向下运动到第三条路线的下方
t12=8; dt=0.05;
while t12>=0.5
t12=t12-dt;
set(c,'xdata',[9;9],'ydata',[t12;t12+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向上运动到第二条路线的上方
t13=1; dt=0.05;
while t13<=8
t13=t13+dt;
set(e,'xdata',[6;6],'ydata',[t13;t13+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,水平运动到第一条路线的最上方
t14=6; dt=0.05;
while t14>=3
t14=t14-dt;
set(e,'xdata',[t14;t14],'ydata',[8;8+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向下运动到第一条路线的下方
t15=8; dt=0.05;
while t15>=1.5
t15=t15-dt;
set(e,'xdata',[3;3],'ydata',[t15;t15+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,竖直向上运动到第二条路线的上方
t16=0.5; dt=0.05;
while t16<=8
t16=t16+dt;
set(d,'xdata',[6;6],'ydata',[t16;t16+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,水平运动到第三条路线的上方
t17=6; dt=0.05;
while t17<=9
t17=t17+dt;
set(d,'xdata',[t17;t17],'ydata',[8;8.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,竖直向下运动到第三条路线的下方
t18=8;dt=0.05;
while t18>=1
t18=t18-dt;
set(d,'xdata',[9;9],'ydata',[t18;t18+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向上运动到第一条路线的上方
t19=1.0;dt=0.05;
while t19<=8
t19=t19+dt;
set(e,'xdata',[3;3],'ydata',[t19;t19+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,水平运动到第三条路线的上方
t20=3;dt=0.05;
while t20<=9
t20=t20+dt;
set(e,'xdata',[t20;t20],'ydata',[8;8.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向下运动到第三条路线的下方
t21=8; dt=0.05;
while t21>=1.5
t21=t21-dt;
set(e,'xdata',[9;9],'ydata',[t21;t21+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置二号长方体木块的运动,竖直向上运动到第一条路线的上方
t22=1.0; dt=0.05;
while t22<=8
t22=t22+dt;
set(b,'xdata',[3;3],'ydata',[t22;t22+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置二号长方体木块的运动,水平运动到第二条路线的上方
t23=3; dt=0.05;
while t23<=6
t23=t23+dt;
set(b,'xdata',[t23;t23],'ydata',[t22;t22+0.5]);
drawnow; set(gcf,'doublebuffer','on'); %消除震动
end
% 设置二号长方体木块的运动,竖直向下运动到第二条路线的最下方
t24=8; dt=0.05;
while t24>=0.5
t24=t24-dt;
set(b,'xdata',[6;6],'ydata',[t24;t24+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向上运动到第三条路线的上方
t25=1.5; dt=0.05;
while t25<=8
t25=t25+dt;
set(e,'xdata',[9;9],'ydata',[t25;t25+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,水平运动到第二条路线的上方
t26=9; dt=0.05;
while t26>=6
t26=t26-dt;
set(e,'xdata',[t26;t26],'ydata',[t25;t25+0.5]);
drawnow; set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向下运动到第二条路线的下方
t27=8; dt=0.05;
while t27>=1.0
t27=t27-dt;
set(e,'xdata',[6;6],'ydata',[t27;t27+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,竖直向上运动到第三条路线的上方
t28=1.5; dt=0.05;
while t28<=8
t28=t28+dt;
set(d,'xdata',[9;9],'ydata',[t28;t28+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,水平运动到第一条路线的上方
t29=9; dt=0.05;
while t29>=3
t29=t29-dt;
set(d,'xdata',[t29;t29],'ydata',[t28;t28+0.5]);
drawnow; set(gcf,'doublebuffer','on'); %消除震动
end
% 设置四号长方体木块的运动,竖直向下运动到第一条路线的下方
t30=8; dt=0.05;
while t30>=1.0
t30=t30-dt;
set(d,'xdata',[3;3],'ydata',[t30;t30+0.5]);
drawnow;
set(gcf,'doublebuffer','on'); %消除震动
end
% 设置五号长方体木块的运动,竖直向上运动到第二条路线的上方
t31=1.0; dt=0.05;
while t31<=8
t31=t31+dt;
set(e,'xdata',[6;6],'yda