声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1957|回复: 4

[转帖]混乱的分形树

[复制链接]
发表于 2005-9-14 17:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
在这个网页上 <BR>http://www.kirupa.com/developer/actionscript/chaos_fractal.htm <BR>提到了分形树的画法: <BR>
<TABLE  cellSpacing=0 cellPadding=10 width="90%">

<TR>
<TD bgColor=#eeeeee><FONT face="Courier New"><BR>/*** Constants ***/ <BR>max_sub_branch = 4 ; <BR>max_sub_angle = 3*Math.PI/4 ; <BR>max_size = 8 ; <BR>branch_length = 50 ; <BR><BR>/*** Function ***/ <BR>function makeBranch ( start_x, start_y, length, angle, size ) { <BR>if ( size &gt; 0 ) { <BR>this.lineStyle ( size, 0x333333, 100 ) ; <BR>this.moveTo ( start_x, start_y ) ; <BR>var end_x = start_x + length * Math.cos ( angle ) ; <BR>var end_y = start_y + length * Math.sin ( angle ) ; <BR>this.lineTo ( end_x, end_y ) ; <BR><BR>var sub_branch = random (max_sub_branch - 1) + 2 ; <BR>var branch_length_dimin = .5 + Math.random()/2 ; <BR>for ( var i=0; i &lt; sub_branch; i ++ ) { <BR>var newLength = length * branch_length_dimin ; <BR>var newAngle = angle + Math.random() * max_sub_angle - max_sub_angle / 2 ; <BR>var newSize = size - 1 ; <BR>makeBranch ( end_x, end_y, newLength, newAngle, newSize ) ; <BR>} <BR>} <BR>} <BR><BR>/*** Function call ***/ <BR>makeBranch ( 200, 300, branch_length, -Math.PI/2, max_size ) ; <BR><BR><BR></FONT></TD></TR></TABLE><BR>把上面这段程序翻译为matlab程序就是: <BR>
<TABLE  cellSpacing=0 cellPadding=10 width="90%">

<TR>
<TD bgColor=#eeeeee><FONT face="Courier New"><BR>function ChaoticFractalTree; <BR>% Chaotic Fractal Tree <BR>% reference: <BR>% http://www.kirupa.com/developer/actionscript/chaos_fractal.htm <BR>% <BR><BR>% Constants: <BR>max_sub_branch = 4; <BR>max_sub_angle=3*pi/4 ; <BR>max_size=6; <BR>branch_length=50; <BR><BR>% function call <BR><BR>hold on <BR>makeBranch(200,300,branch_length,pi/2,max_size); <BR>title('please double click the mouse and redraw') <BR>set(gcf,'ButtonDownFcn',['t=get(gcf,''SelectionType'');',... <BR>   'if t(1)==''o'';close;',... <BR>   'ChaoticFractalTree;end']) <BR>%% Function <BR>function makeBranch (start_x,start_y,leng,angl,siz); <BR>% Constants: <BR>max_sub_branch = 4; <BR>max_sub_angle=3*pi/4 ; <BR>branch_length=50; <BR>if siz&gt;0; <BR>   z=start_x+start_y*i; <BR>   z_end=z+leng*exp(i*angl); <BR>   plot([z,z_end],'linewidth',siz); <BR>   sub_branch=rand*(max_sub_branch-1)+2; <BR>   branch_length_dimin=.5+rand/2; <BR>   end_x=real(z_end); <BR>   end_y=imag(z_end); <BR>   for k=0:sub_branch; <BR>       newLength=leng*branch_length_dimin; <BR>       newAngle =angl+rand*max_sub_angle-max_sub_angle/2; <BR>       newSize=siz-1; <BR>       makeBranch(end_x,end_y,newLength,newAngle,newSize); <BR>   end <BR>end <BR></FONT></TD></TR></TABLE><BR>读者使用下面这段语句就可以实现鼠标双击重绘: <BR>
<TABLE  cellSpacing=0 cellPadding=10 width="90%">

<TR>
<TD bgColor=#eeeeee><FONT face="Courier New"><BR>axes; <BR>title('please double click the mouse and redraw') <BR>set(gcf,'ButtonDownFcn',['t=get(gcf,''SelectionType'');',... <BR>   'if t(1)==''o'';cla;',... <BR>   'ChaoticFractalTree;end']) <BR></FONT></TD></TR></TABLE>

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2005-9-21 08:46 | 显示全部楼层
这个看着很眼熟阿
发表于 2005-9-21 19:32 | 显示全部楼层
是哪个的程序啊&gt;
发表于 2005-9-21 20:13 | 显示全部楼层
应该出自这里:<a href="http://luobo.yculblog.com/post.807548.html" target="_blank" ><BR>http://luobo.yculblog.com/post.807548.html</A>
发表于 2005-11-27 02:31 | 显示全部楼层
呵呵,推广吗
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-14 23:41 , Processed in 0.070530 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表