非常漂亮的分形树
<P>function fractree(X,Y,length,direction)</P><P>%Script draws a fractal tree for a specified<BR>% number of branches, angle & distance factor ...<BR>%<BR>% Each branch is 'distance-factor' times the last in length<BR>%and leans off to the left/right at the given angle. The depth<BR>%of the tree limits the total number of branches drawn.<BR>% Random trees can be generated from an integer seed. </P>
<P><BR>global angle distFactor branches minLen branchFac;</P>
<P>ifnargin<1</P>
<P>%For initial call, get user input for parameters</P>
<P>branchFac = [ 1 -1 0 ];</P>
<P>fprintf('\nFractal Trees\n\n');<BR>angle=pi*(input('Enter angle (0 - 180, zero for random) : ')/180);<BR>distFactor=input('Enter distance factor (0 - 1, zero for random) : ');<BR>ifangle==0|distFactor==0<BR> seed=input('Enter the random number seed (integer) : ');<BR> rand('seed',seed);<BR>end<BR>branches=input('Enter the number of branches (2 or 3) : ');<BR>maxDepth=input('Enter the maximum depth of the tree : ');</P>
<P>%Thanks to Ken Crounse for the stopping criterium<BR>if distFactor~=0<BR> minLen=distFactor.^(maxDepth-0.5);<BR>else<BR> minLen=0.5.^(maxDepth-0.5);<BR>end</P>
<P>%Declare figure window for output<BR>figure(1);<BR>axis('square','equal','off');<BR>hold on<BR>fractree(0,0,1,0);<BR>hold off<BR>disp('');</P>
<P>else</P>
<P>%Calculate end position of the branch<BR>newX=X+(length*sin(direction));<BR>newY=Y+(length*cos(direction));</P>
<P>%Set the colour for a branch, twig or leaf<BR>colStr='r-';<BR>if length<0.25<BR> colStr='g-';<BR>end<BR>if length<0.03125<BR> colStr='w-';<BR>end</P>
<P>%Draw the branch<BR>plot(,,colStr);</P>
<P><BR>%If the branch is reasonably long...<BR>if length>minLen</P>
<P>%extend new branches to it<BR> for brNo=1:branches</P>
<P>%Calculate length and direction of the next branch<BR> if distFactor==0<BR> newLength=length*( (rand(1)*.5) + .25 );<BR> else<BR> newLength=length*distFactor;<BR> end</P>
<P> if angle==0<BR> newDir=direction+( ((rand(1)*1.7453)+0.1745) * branchFac(brNo) );<BR> else<BR> newDir=direction+(angle*branchFac(brNo));<BR> end</P>
<P>%Call the routine again to draw next branch<BR> fractree(newX,newY,newLength,newDir);</P>
<P> end</P>
<P>end</P>
<P>end</P>
回复:(brianlei)非常漂亮的分形树
我怎么画不出来?<BR><BR>总是出现错误<BR>Error in ==> D:\MATLAB6p5\work\abc.m<BR>On line 41==> fractree(0,0,1,0); 我也老是有错,画不出来回复:(mantou)我也老是有错,画不出来
<BR>在命令窗口输入:fractree回车后<BR>就有提示.按提示输入,就可以.<BR>不过,建议树深不要取过大值!否则将花费很多时间.<BR><BR>回复:(brianlei)非常漂亮的分形树
<P>我也画不出非常漂亮的分形树<BR>出现这样的错误呀<BR>??? Undefined function or variable 'fractree'.</P>回复:(woainiQQ)回复:(brianlei)非常漂亮的分形...
<P>确定其M文件放在MATLAB安装目录下的work文件夹里?</P> <P>我也没画出来啊</P>yeah
确实非常漂亮; <P>不错</P>回复:(brianlei)回复:(woainiQQ)回复:(brianl...
是放在那个文件夹里,没有用,出现了同样的错误报告!请问这是怎么回事? 不好意思,确实可以,很漂亮!<BR>M文件的文件名要和函数名一样才行!惭愧呀! beautiful! 差点搞到我死机。。。。厉害的,哈哈回复:(66666yy) 差点搞到我死机。。。。 厉害的,...
<DIV class=quote><B>以下是引用<I>66666yy</I>在2006-1-8 11:02:48的发言:</B><BR>差点搞到我死机。。。。厉害的,哈哈</DIV><br>选的分叉数太多了吧 <P>very good</P>
页:
[1]
2