frogfish 发表于 2005-9-14 17:08

[转帖]混乱的分形树

在这个网页上 <BR>http://www.kirupa.com/developer/actionscript/chaos_fractal.htm <BR>提到了分形树的画法: <BR>
<TABLEcellSpacing=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>
<TABLEcellSpacing=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(,'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>
<TABLEcellSpacing=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>

zjliu 发表于 2005-9-21 08:46

这个看着很眼熟阿

xopowomimi 发表于 2005-9-21 19:32

是哪个的程序啊&gt;

zjliu 发表于 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>

superliu 发表于 2005-11-27 02:31

呵呵,推广吗
页: [1]
查看完整版本: [转帖]混乱的分形树