如何用matlab画动态花,【花式】matlab实现落叶动态展示

【花式】matlab实现落叶动态展示

【花式】matlab实现落叶动态展示

function leafpile3D(N,leaftype,motion)

%leafpile3D(N,leaftype) makes a random falling pile of N leaves

% of leaftype 'oak' or 'maple' or 'mixed'. N. Barlow 8/31/20

%leafpile3D(N) makes a falling mixed pile of N leaves.

%leafpile3D makes a falling pile of 60 mixed leaves.

%leafpile3D(N,leaftype,0) will suspend the leaves (no falling)

%There is no drag enforced. It is up to the user to incorporate a drag

%model on line 39. Have fun!

%The mathematical functions describing the leaf shapes were created by Hamid Naderi

%Yeganeh and given at https://blogs.scientificamerican.com/guest-blog/how-to-draw-with-math/

if nargin==0,N=60; leaftype='mixed'; motion=1; end

if nargin==1, leaftype='mixed'; motion=1; end

if nargin==2, motion=1;end

%types of leaves

if strcmp(leaftype,'maple')==1

type=cell(1,N); type(:)={'maple'};

elseif strcmp(leaftype,'oak')==1

type=cell(1,N); type(:)={'oak'};

else

type=cell(1,N);type(:)={'maple'};

r=rand(1,N);type(r<=0.5)={'oak'};

end

%make some random leaf info

for n=1:N

xv(n)=(-1)^randi(2)*rand; yv(n)=(-1)^randi(2)*rand; %random (x,y)

z0(n)=(-1)^randi(2)*rand; %random initial heights

tv(n)=(-1)^randi(2)*rand;bv(n)=(-1)^randi(2)*rand; gv(n)=(-1)^randi(2)*rand; %random rotations

cv(n)=randi(N); %random colors

end

g=9.81; %acceleation of gravity in m/s^2

if motion==1

for t=0:0.1:1000

%%YOUR MISSION: EDIT LINE BELOW TO INCORPORATE DRAG

z=z0+1/2*g*t^2; %here, z is positive down

%%%%%%%%%%%%%%%%

makeleaves3D(N,type,xv,yv,-z,tv,bv,gv,cv)

drawnow

if max(-z)<=-1

break

end

end

else

makeleaves3D(N,type,xv,yv,-z0,tv,bv,gv,cv)

end

function makeleaves3D(N,type,xv,yv,zv,tv,bv,gv,cv)

clf; C=autumn(N);

set(gca,'color',[129/256 182/256 221/256]);

hold on; axis equal;axis([-1.2 1.2 -1.2 1.2 -1.2 1.2]); box on; view(45,30);

for n=1:N

if strcmp(type(n),'oak')==1

oak(xv(n),yv(n),max(-1.1,zv(n)),0.5,tv(n)*2*pi,bv(n)*pi/10,gv(n)*pi/10,C(cv(n),:))

elseif strcmp(type(n),'maple')==1

maple(xv(n),yv(n),max(-1.1,zv(n)),0.12,tv(n)*2*pi,bv(n)*pi/10,gv(n)*pi/10,C(cv(n),:))

end

end

fill3([-1.2 1.2 1.2 -1.2],[-1.2 -1.2 1.2 1.2],[-1.2 -1.2 -1.2 -1.2],[34/256 139/256 34/256])

42e832a481b5ee12434b4fdb7ce4fba4.png

完整代码添加QQ1575304183

【花式】matlab实现落叶动态展示相关教程

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值