资源描述:
《matlab小球跳动程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、figure(1);axis([-5.1,5,-0.05,1.05]);holdon;axis('off');fill([4.12,4.22,4.22,4.12],[-0.05,-0.05,1.05,1.05],'y');fill([-5,-3.2,-3.2,-5],[-0.05,-0.05,0,0],'g');fill([-3.2,-2.8,-2.8,-3.2],[-0.05,-0.05,0.2,0.2],'g');fill([-3.2,-1.4,-1.4,-3.2],[0.2,0.2,0.25,0.
2、25],'g');fill([-1.4,-1,-1,-1.4],[0.2,0.2,0.45,0.45],'g');fill([-1.4,0.4,0.4,-1.4],[0.45,0.45,0.5,0.5],'g');fill([0.4,0.8,0.8,0.4],[0.45,0.45,0.7,0.7],'g');fill([0.4,2.0,2.0,0.4],[0.7,0.7,0.75,0.75],'g');fill([2.0,2.3,2.3,2.0],[-0.05,-0.05,0.75,0.75],'g')
3、;fill([2.3,4.12,4.12,2.3],[-0.05,-0.05,0,0],'g');%x2=line([-5,5],[0.25,0.25],'color','g','linestyle','-','makersize',50)%line([-5,5],[0.5,0.5],'color','b','linestyle','-','markersize',50)%line([-5,5],[0.75,0.75],'color','b','linestyle','-','markersize',5
4、0)head=line(-5,1,'color','r','linestyle','.','erasemode','xor','markersize',60);%body=line(-5,1,'color','b','linestyle','-','erasemode','none');>>while1t=4;dt=0.001;w=0;dw=0.001;w=0;whilet<=4.12t=dt+t;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',
5、t,'ydata',y);%set(body,'xdata',t,'ydata',y);drawnow;endw=0;whilet>=2.11t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,'ydata',y);%set(body,'xdata',t,'ydata',y);drawnow;endw=0;whilet>=1.11t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)/4+1;set(hea
6、d,'xdata',t,'ydata',y);%set(body,'xdata',t,'ydata',y);drawnow;endw=-0.71;whilet>=-0.62t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)/2+1;set(head,'xdata',t,'ydata',y);%set(body,'xdata',t,'ydata',y);drawnow;endw=-0.71;whilet>=-2.31t=t-dt;ifw<=1w=dw+w;elsew=-1;e
7、ndy=(-w*w)/2+0.75;set(head,'xdata',t,'ydata',y);%set(body,'xdata',t,'ydata',y);drawnow;endw=-0.71;whilet>=-4t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)/2+0.5;set(head,'xdata',t,'ydata',y);%set(body,'xdata',t,'ydata',y);drawnow;endfori=0:0.01:200y=i+2;if(y>1
8、99)endendend