# 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 on
drawnow;

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==0
r=rand;
if r<0.85
x=A1*x+b1;
elseif r<0.92
x=A2*x+b2;
elseif r<0.99
x=A3*x+b3;
else
x=A4*x;
end
plot(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)');
end
end



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 on
drawnow;

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==0
r=rand;
if r<1/3
x=A*x+b1;
elseif r<2/3
x=A*x+b2;
else
x=A*x+b3;
end
plot(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)');
end
end


10-12 805
03-26 7万+

07-24 7万+
08-06 2万+
07-08 19万+
01-17 3880
08-22 1万+
03-17 13万+