Fibonacci word/fractal: Difference between revisions

→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output section, provided a mechanism for not displaying the graph to the terminal, split compound statements, optimized the inner DO loop for the output.
m (→‎{{header|REXX}}: reduced the scale (font-size) of the output.)
(→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output section, provided a mechanism for not displaying the graph to the terminal, split compound statements, optimized the inner DO loop for the output.)
Line 1,902:
About half of the REXX program is dedicated to plotting the appropriate characters.
 
TheIf outputthe order of thisthe REXX programgraph is writtennegative, to  the screengraph asisn't welldisplayed asto athe diskterminal filescreen.
 
<lang rexx>/*REXX program generates a Fibonacci word, then displays the fractal curve. */
The output of this REXX program is always written to a disk file &nbsp; (named &nbsp; FIBFRACT.OUT).
parse arg ord . /*obtain optional arguments from the CL*/
<lang rexx>/*REXX program generates a Fibonacci word, then (normally) displays the fractal curve. */
if ord=='' then ord=23 /*Not specified? Then use the default*/
s=FibWord(ord)parse arg order . /*obtain theoptional arguments orderfrom the of Fibonacci word.CL*/
if ordorder=='' | then ordorder==23 "," then order= 23 /*Not specified? Then use the default*/
x=0; maxX=0; dx=0; b=' '; @.=b; xp=0
tell= order>=0 y=0; /*Negative order? maxY=0;Then don't dy=1; @display.0.0=.; yp=0*/
s= FibWord( abs(order) ) do n=1 for length(s); x=x+dx; y=y+dy /*advanceobtain the plot fororder the nextof point.Fibonacci word.*/
x= 0; maxX= 0; dx= 0; b= ' '; @. = b; xp= 0
maxX=max(maxX,x); maxY=max(maxY,y) /*set the maximums for displaying plot.*/
c y='│' 0; if dx\= maxY= 0; then c dy="─" 1; if n==1 then c='┌' /*is@.0.0= this.; the first plot?*/ yp= 0
do n=1 for length(s); x= x + dx; y= y + dy /*advance the plot for the next point. */
@.x.y=c /*assign a plotting character for curve*/
ifmaxX= @max(xp-1maxX,yp x)\==b; then if @maxY= max(xpmaxY,yp-1 y)\==b then call @ xp,yp,'┐'/*set the maximums /*fix─upfor adisplaying cornerplot.*/
if @(xp-1,yp)\==b then if @(xp,yp+1)\==b then call @ xp,yp, c= '' /* " " " /*glyph (character) used for the plot. */
if @(xp+1,yp)dx\==b0 then ifc= "─" @(xp,yp+1)\==b then call @ xp,yp,'└' /* " " " /*if x+dx isn't zero, use this char.*/
if @(xp+1,yp)\n==b1 then if then @(xp,yp-1)\=c=b '┌' then call @ xp,yp,'┌' /* " " " /*is this the first part to be graphed?*/
xp=@.x;.y= c yp=y; z=substr(s,n,1) /*save old x,y; /*assign plota plotting character. for curve*/
if @(xp-1, yp)\==b then if @(xp, yp-1)\==b then call @ xp,yp,'┐' /*fix─up a corner*/
if @(xp-1, yp)\==b then if @(xp, yp+1)\==b then call @ xp,yp,'┘' /* " " " */
if @(xp+1, yp)\==b then if @(xp, yp-1)\==b then call @ xp,yp,'┌' /* " " " */
if @(xp+1, yp)\==b then if @(xp, yp+1)\==b then call @ xp,yp,'└' /* " " " */
xp= x; yp= y /*save the old x & y coördinates.*/
parse arg ord . z= substr(s, n, 1) /*obtainassign a optionalplot argumentscharacter fromfor the CLgraph*/
if z==1 then iterate /*Is Z equal to unity? Then ignore it.*/
ox= dx; oy= dy; dx=0; dy=0 /*save DX,DY as the old versions. */
ddx=-n//2 0; if d= dy= 0 then d=1 /*determinedefine DX,DY " " new " the sign for the chirality.*/
if oy\d==0 -n//2; then dx=-sign(oy)*d if d==0 then d= 1 /*Going north|south? Go /*determine the sign east|westfor the chirality.*/
if oxoy\==0 then dydx= -sign(oxoy) * d /*Going "north│south? Go east|west? " south|north */
if ox\==0 then dy= sign(ox) * d /* " east│west? " south|north */
end /*n*/
 
call @ x, y, '∙' /*set the last point that was plotted. */
 
do r=maxY to 0 by -1; _= /*show single row at a time, top first.*/
do c=0 tofor maxX+1; _= _ || @.c.r; end /*c*/;add a plot character _=strip(_, 'T'glyph) /*build ato line.*/
if _=='' thenend /*c*/ iterate /*if the[↑] line isconstruct blank,a thenline ignorechar itby char. */
say _;= strip(_, 'T') call lineout "FIBFRACT.OUT", _ /*displayconstruct thea line; alsoof writethe to diskgraph. */
end if _=='' /*r*/ then iterate /*Is the line blank? Then ignore it. /* [↑] only display the non-blank rows*/
exit if tell then say _ /*stickDisplay athe forkline into it,the terminal we're? all done. */
call lineout "FIBFRACT.OUT", _ /*write graph to disk (FIBFRACT.OUT). */
end /*r*/ /* [↑] only display the non-blank rows*/
exit 0 @.x.y=c /*assignstick a plottingfork characterin forit, we're all done. curve*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: parse arg xx,yy,p; if arg(3)=='' then return @.xx.yy; @.xx.yy= p; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
FibWord: procedure; parse arg x; !.= 0; !.1=1 1 /*obtain the order of Fibonacci word. */
do k=3 to x; k1=k-1; k2=k-2 /*generate the Kth " " */
!.k=!.k1 || !.k2 k1= k-1; k2= k - 2 /*constructcalculate the next K-1 & K-2 " " shortcut.*/
!.k= !.k1 || !.k2 /*construct the next Fibonacci word. */
end /*k*/ /* [↑] generate a " " */
return !.x /*return the Xth " " */</lang>
'''{{out|output''' |text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 17 </tt>}}
<br><br>(The output is shown <sup>1</sup>/<sub>8</sub> size.)
<b>