x0=0;y0=0;
sita=0:pi/20:2*pi;
cx=R*sin(sita);
cy=R*cos(sita)+R;
xt=v0*t;
x=v0*t-R*sin(v0/R*t);
y=R-R*cos(v0/R*t);
% plot(x,y);
line([0,6*R*pi],[0,0],'color','y');
title('MatLab动画:摆线运动');
axis([-R,20,0,10]);
axis('off','equal');%
point=line(x0,y0,'color','b','linestyle','.','erasemode','none','markersize',5);
circle0=line(cx,cy,'color','r','linestyle','--','erasemode','xor','markersize',1);%
line0=line([0,0],[R,0],'color','r','linestyle','-','erasemode','xor','markersize',1);%
n=length(t);
i=1;
while 1 %条件表达式
temp=xt(i);
set(circle0,'xdata',cx+temp);drawnow;
set(line0,'xdata',[temp,x(i)],'ydata',[R,y(i)]);drawnow;
set(point,'xdata',x(i),'ydata',y(i));
drawnow;
if i==n
di=-1;set(point,'erasemode','background');
end
if i==1
di=1;set(point,'erasemode','none');
end
i=i+di;
end