600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Matlab创建蕨形叶和塞平斯基三角形的图形用户界面(wzl)

Matlab创建蕨形叶和塞平斯基三角形的图形用户界面(wzl)

时间:2021-11-25 03:23:04

相关推荐

Matlab创建蕨形叶和塞平斯基三角形的图形用户界面(wzl)

首先了解蕨形叶

function fern1%两个组件h1=uicontrol('style','togglebutton','string','Stop');h2=axes('XLim',[-3 3],'YLim',[0,10],'Position',[0.15,0.15,0.75,0.75]);%画蕨形叶图x=[0.5;0.5];plot(h2,x(1),x(2),'.','color',[0 2/3 0],'markersize',1);axis([-3 3 0 10]);hold ondrawnow;A1=[0.85 0.04;-0.04 0.85]; b1=[0;1.6];A2=[0.2 -0.26;0.23 0.22]; b2=[0;1.6];A3=[-0.15 0.28;0.26 0.24]; b3=[0;0.44];A4=[0 0;0 0.16];while h1.Value==0r=rand;if r<0.85x=A1*x+b1;elseif r<0.92x=A2*x+b2;elseif r<0.99x=A3*x+b3;elsex=A4*x;endplot(h2,x(1),x(2),'.','color',[0 2/3 0],'markersize',1);drawnow;end%按钮的响应h1.Callback=@stop2close;function stop2close(hobject,eventdata)set(hobject,'string','close','callback','close(gcf)');endend

只需在这蕨形叶基础上进行修改即可

function Sierpinski%两个组件h1=uicontrol('style','togglebutton','string','Stop');h2=axes('Position',[0.15,0.15,0.75,0.75]);%画蕨形叶图x=[0,0];plot(h2,x(1),x(2),'.','color',[0 2/3 0],'markersize',1);axis([-0.3 1.3 0 1.3]);hold ondrawnow;A1=[0.85 0.04;-0.04 0.85];b1=[0;0];b2=[1/2;0];b3=[1/4;sqrt(3)/4];while h1.Value==0r=rand;if r<1/3x=A*x+b1;elseif r<2/3x=A*x+b2; elsex=A*x+b3;endplot(h2,x(1),x(2),'.','color',[0 2/3 0],'markersize',1);drawnow;end%按钮的响应h1.Callback=@stop2close;function stop2close(hobject,eventdata)set(hobject,'string','close','callback','close(gcf)');endend

画出图像:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。