一个能画出好看图片的小程序呀
补动图:
树枝长度,树枝角度都可以调的
完整代码:
function binary2 hold on,axis equal axis(0.5+[0,40,0,40]) set(gca,'xtick',[],'ytick',[],'xcolor','w','ycolor','w') set(gca,'color','k') length_trunk=6; width_trunk=3; k1=0.8;k2=0.8; number_branch=10; alp=pi/10; length_branch=k1*length_trunk; width_branch=k2*width_trunk; trunk=[20,0;20,length_trunk]; plot(trunk(:,1),trunk(:,2),'w','Linewidth',width_trunk) begins=[trunk(2,:),pi/2]; grow=begins; for i=1:number_branch ag=grow(:,3); l=length(ag); parta=[length_branch*cos(ag+ones(l,1)*alp),length_branch*sin(ag+ones(l,1)*alp),ones(l,1)*alp]; partb=[length_branch*cos(ag-ones(l,1)*alp),length_branch*sin(ag-ones(l,1)*alp),-ones(l,1)*alp]; parta=parta+grow; partb=partb+grow; congress=[parta;partb]; grow=[grow;grow]; pla=[grow(:,1),congress(:,1)]; plb=[grow(:,2),congress(:,2)]; pla=pla';plb=plb'; plot(pla,plb,'w','Linewidth',width_branch) grow=congress; length_branch=k1*length_branch; width_branch=k2*width_branch; pause(0.05) end end