|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
- function solar_system
- % 模拟太阳系运动
- t=linspace(0,2*pi,100);
- fill(cos(t),sin(t),'r');
- hold on;
- plot(4*cos(t),sin(t)*4,'k');
- set(gca,'position',[0 0.11 0.775 0.815])
- a=0.1;b=0;
- xe=4*cos(a)+cos(t)*0.6;
- ye=4*sin(a)+sin(t)*0.6;
- He=fill(xe,ye,'b');
- xm=4*cos(a)+cos(b);
- ym=4*sin(a)+sin(b);
- set(gcf,'doublebuffer','on');
- Hm=plot(xm,ym,'c.','markersize',24);
- aa=gca;
- axis([-6,6,-6,6]);
- axis square;
- k=1;da=0.1;db=0.5;
- xlabel('Please press "space" key and stop this program!',...
- 'fontsize',12,'color','r');
- title('simulate solar system')
- axes('position',[0.75,0.11,0.25,0.8]);
- fill(0.2+cos(t)*0.18,0.75+sin(t)*0.08,'r');
- ylim([0,1]);xlim([0,0.9]);
- text(0.5,0.75,'Sun');hold on;
- fill(0.2+cos(t)*0.11,0.5+sin(t)*0.05,'b');
- text(0.5,0.5,'Earth');
- plot(0.2,0.3,'c.','markersize',24);
- text(0.5,0.3,'Moon');
- axis off
- axes(aa);
- while k;
- s=get(gcf,'currentkey');
- if strcmp(s,'space');
- clc;k=0;
- end
- a=a+da;
- b=b+db;
- xe=4*cos(a)+cos(t)*0.6;
- ye=4*sin(a)+sin(t)*0.6;
- xm=4*cos(a)+cos(b);
- ym=4*sin(a)+sin(b);
- set(He,'xdata',xe,'ydata',ye);
- set(Hm,'xdata',xm,'ydata',ym);
- pause(0.1);
- if a<80;
- plot(xm,ym);
- end
- end
- figure(gcf);
复制代码
[ 本帖最后由 suffer 于 2006-10-9 19:42 编辑 ] |
|