Matlab 版 (精华区)
发信人: zjliu (秋天的萝卜), 信区: Matlab
标 题: [发布程序] 动态的Von Koch分形曲线
发信站: 哈工大紫丁香 (Fri Jun 4 22:44:34 2004), 转信
close all
figure;
x1=[1 2 2.5 3 4];
y1=[0 0 0 0 0];
h1=plot(x1,y1,'linewidth',2,'erasemode','xor');
axis equal
axis off
for g=linspace(0,1,40)*sin(pi/3);
y1(3)=g;
set(h1,'ydata',y1);
drawnow;
pause(0.15)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x2=x1(1);
y2=y1(1);
for k=2:length(x1);
t=linspace(x1(k-1),x1(k),4);
tt=[t(2),mean(t),t(3:4)];
x2=[x2,tt];
t=linspace(y1(k-1),y1(k),4);
tt=[t(2),mean(t),t(3:4)];
y2=[y2,tt];
end
A=angle((y2(4:4:end)-y2(2:4:end))*i+(x2(4:4:end)-x2(2:4:end)));
for g=linspace(0,1,40)*sin(pi/3)/3;
y2(3:4:end)=(y2(4:4:end)+y2(2:4:end))/2+imag(g*exp(i*(A+pi/2)));
x2(3:4:end)=(x2(4:4:end)+x2(2:4:end))/2+real(g*exp(i*(A+pi/2)));
set(h1,'ydata',y2,'xdata',x2);
drawnow;
pause(0.15)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x3=x2(1);
y3=y2(1);
for k=2:length(x2);
t=linspace(x2(k-1),x2(k),4);
tt=[t(2),mean(t),t(3:4)];
x3=[x3,tt];
t=linspace(y2(k-1),y2(k),4);
tt=[t(2),mean(t),t(3:4)];
y3=[y3,tt];
end
A=angle((y3(4:4:end)-y3(2:4:end))*i+(x3(4:4:end)-x3(2:4:end)));
for g=linspace(0,1,40)*sin(pi/3)/9;
y3(3:4:end)=(y3(4:4:end)+y3(2:4:end))/2+imag(g*exp(i*(A+pi/2)));
x3(3:4:end)=(x3(4:4:end)+x3(2:4:end))/2+real(g*exp(i*(A+pi/2)));
set(h1,'ydata',y3,'xdata',x3);
drawnow;
pause(0.15)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x4=x3(1);
y4=y3(1);
for k=2:length(x3);
t=linspace(x3(k-1),x3(k),4);
tt=[t(2),mean(t),t(3:4)];
x4=[x4,tt];
t=linspace(y3(k-1),y3(k),4);
tt=[t(2),mean(t),t(3:4)];
y4=[y4,tt];
end
A=angle((y4(4:4:end)-y4(2:4:end))*i+(x4(4:4:end)-x4(2:4:end)));
for g=linspace(0,1,40)*sin(pi/3)/27;
y4(3:4:end)=(y4(4:4:end)+y4(2:4:end))/2+imag(g*exp(i*(A+pi/2)));
x4(3:4:end)=(x4(4:4:end)+x4(2:4:end))/2+real(g*exp(i*(A+pi/2)));
set(h1,'ydata',y4,'xdata',x4);
drawnow;
pause(0.15)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
╔═══════════════════╗
║★★★★★友谊第一 比赛第二★★★★★║
╚═══════════════════╝
※ 修改:·zjliu 于 May 10 20:25:27 修改本文·[FROM: 202.118.229.162]
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.229.*]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:14.437毫秒