- 积分
- 8044
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-5-29
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
%本程序纯属娱乐
%原文地址:http://www.matlabsky.com/thread-6473-1-1.html
%将下面程序复制一下,粘贴到m文件,保存运行即可
hold on
fill([-3,13,13,-3],[1,1,11,11],[0,1,0])
fill([-2,12,12,-2],[2,2,10,10],[0,0.5,0])
axis equal off
Ball1=line(-2,2,'Color','g','Marker','.','Markersize',85);
Ball2=line(12,2,'Color','g','Marker','.','Markersize',85);
Ball3=line(-2,10,'Color','g','Marker','.','Markersize',85);
Ball4=line(12,10,'Color','g','Marker','.','Markersize',85);
% RX=-1.7+fix(13.7*rand(1,2));RY=2.3+fix(7.7*rand(1,2));
RX=[-1 3];RY=[3 6];
t=0:0.01:2*pi;
ball1=plot(0.3*cos(t)+RX(1),0.3*sin(t)+RY(1),'Color','r');
ball2=plot(0.3*cos(t)+RX(2),0.3*sin(t)+RY(2),'Color','g');
theta1=atand((10-RY(2))/(12-RX(2)));
xx=RX(2)-0.6*cosd(theta1);yy=RY(2)-sind(theta1);
theta2=atand((yy-RY(1))/(xx-RX(1)));
x=RX(1);dx=0.005;y=inf;
while norm([x,y]-[xx yy])>0.01
x=x+dx;y=tand(theta2)*(x-RX(1))+RY(1);
set(ball1,'xdata',0.3*cos(t)+x,'ydata',y+0.3*sin(t))
drawnow
end
x=RX(2);x2=xx;y1=inf;X=[];Y=[];
while norm([x,y1]-[12 10])>0.01
x=x+dx;y1=tand(theta1)*(x-12)+10;
x2=x2-dx;y2=-1/tand(theta2)*(x2-xx)+yy;
X=[X x2];Y=[Y y2];
if y2>=9.7
x2=(yy-9.7)*tand(theta2)+xx;y2=9.7;
end
set(ball1,'xdata',0.3*cos(t)+x2,'ydata',y2+0.3*sin(t))
set(ball2,'xdata',0.3*cos(t)+x,'ydata',y1+0.3*sin(t))
drawnow
end
text(6,12,'哇!进球了!你好棒呀','fontname',...
'隶书','fontsize',20,'Horizontalalignment','center')
|
|