万有引力搜索matlab程序,[转载]matlab 万有引力动画

h=figure('name','万有引力的发现');

set(h,'color','k');

axis([-10 10 -10 10]);%设坐标轴

fill([-10,10,10,-10],[-10,-10,10,10],'k');%定坐标轴

axis off;

hold on;

%%画月亮

line(7,8,'color','y','linestyle','.','markersize',180);

%%画大树

line([-2,-2],[-10,-2],'color',[0.1,0.8,0.1],'linestyle','-','linewidth',65);

fill([-8,-2,4],[-2,1,-2],'g');

fill([-6,-2,2],[-1,1,-1],'g');

fill([-4,-2,0],[0,1,0],'g');

%画小树

line([-7,-7],[-10,-7],'color',[0.1,0.8,0.1],'linestyle','-','linewidth',45);

fill([-9,-7,-5],[-7,-5,-7],'g');

fill([-8,-7,-6],[-6,-5,-6],'g');

% 画小人

a1=line(1,-8,'Color','r','linestyle','.', 'markersize',70);

a2=line([1 1],[-8 -10],'color','r','linewidth',2);

a3=line([1 2],[-9 -9.5],'color','r','linewidth',2);

a4=line([1 2],[-9 -9.8],'color','r','linewidth',2);

a5=line([1 2.5],[-10 -10],'color','r','linewidth',2);

a6=line([1 2.5],[-10 -9.5],'color','r','linewidth',2);

%画苹果

a7=line(3,-3,'Color','r','linestyle','.', 'markersize',65);

a8=line([3 2.5],[-3 -2],'color','g','linewidth',2);

a9=line(-6,-3,'Color','r','linestyle','.', 'markersize',65);

a10=line([-6 -6.5],[-3 -2],'color','g','linewidth',2);

%画山

line(8,2,'color',[0.1,0.6,0.3],'linestyle','>','linewidth',50);

line(6,2,'color',[0.1,0.6,0.3],'linestyle','>','linewidth',40);

line(5,2,'color',[0.1,0.6,0.3],'linestyle','>','linewidth',50);

line(2,3,'color',[0.1,0.6,0.3],'linestyle','^','linewidth',40);

line(-9,2,'color',[0.1,0.6,0.3],'linestyle','^','linewidth',70);

line(-7,2,'color',[0.1,0.6,0.3],'linestyle','^','linewidth',50);

%苹果落地

t=0;

dt=0.1;

while t<6

t=t+dt; set(a7,'xdata',[3],'ydata',[-3-t]);

set(a8,'xdata',[3 2.5],'ydata',[-3-t -2-t]);

pause(0.001)

set(gcf,'doublebuffer','on') %消除抖动

end

%题词

e1=text(4, -8,'恩?苹果为什么会落地呢!','fontsize',12,'color','r');

pause(0.2)

set(gcf,'doublebuffer','on') %消除抖动

set(e1,'visible','off')

e2=text(4, -8,'牛顿经过深思熟虑','fontsize',12,'color','r');

pause(0.2)

set(gcf,'doublebuffer','on') %消除抖动

set(e2,'visible','off')

e3=text(4, -8,'并在实验室通过进一步实验','fontsize',12,'color','r');

pause(0.2)

set(gcf,'doublebuffer','on') %消除抖动

set(e3,'visible','off')

e4=text(4, -8,'终于总结出万有引力定律','fontsize',12,'color','r');

pause(0.3)

set(gcf,'doublebuffer','on') %消除抖动

text(-7,10,'万有引力的发现','backgroundcolor','r','color','g',...

'margin',4,'rotation',0,'fontsize',25,'fontweight','light');%设标题

%画闪烁的星星

m=moviein(30); %创建帧矩阵

for j=1:15

line(8,6,'color','r','linestyle','h','linewidth',0.5*j);

line(5,8,'color','b','linestyle','h','linewidth',0.5*j);

line(7,4,'color','r','linestyle','h','linewidth',0.5*j);

line(4,6,'color','m','linestyle','h','linewidth',0.5*j);

line(5,6,'color','m','linestyle','h','linewidth',0.5*j);

line(2,6,'color','b','linestyle','h','linewidth',0.5*j);

line(2,8,'color','r','linestyle','h','linewidth',0.5*j);

line(-2,4,'color','m','linestyle','h','linewidth',0.5*j);

line(-1,7,'color','b','linestyle','h','linewidth',0.5*j);

line(-4,5,'color','r','linestyle','h','linewidth',0.5*j);

line(-2,5,'color','b','linestyle','h','linewidth',0.5*j);

line(-3,8,'color','m','linestyle','h','linewidth',0.5*j);

line(-8,8,'color','m','linestyle','h','linewidth',0.5*j);

line(-6,7,'color','r','linestyle','h','linewidth',0.5*j);

line(-9,6,'color','b','linestyle','h','linewidth',0.5*j);

line(-5,8,'color','b','linestyle','h','linewidth',0.5*j);

m(:,j)=getframe; %捕获动画帧

end

%clf;

movie(m,30) %回放动画

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值