matlab 小程序二叉树

一个能画出好看图片的小程序呀
补动图:
在这里插入图片描述
在这里插入图片描述
树枝长度,树枝角度都可以调的

完整代码

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

slandarer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值