Anonymous user
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.
<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 (named FIBFRACT.OUT).
parse arg ord . /*obtain optional arguments from the CL*/▼
▲<lang rexx>/*REXX program generates a
if ord=='' then ord=23 /*Not specified? Then use the default*/▼
x=0; maxX=0; dx=0; b=' '; @.=b; xp=0▼
tell= order>=0
s= FibWord( abs(order) )
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*/▼
if
if
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.*/
▲
if z==1 then iterate /*Is Z equal to unity? Then ignore it.*/
ox= dx;
if
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; _=
do c=0
call lineout "FIBFRACT.OUT", _ /*write graph to disk (FIBFRACT.OUT). */
end /*r*/ /* [↑] only display the non-blank rows*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: parse arg xx,yy,p; if arg(3)=='' then return @.xx.yy; @.xx.yy= p;
/*──────────────────────────────────────────────────────────────────────────────────────*/
FibWord: procedure; parse arg x;
do k=3 to x
!.k= !.k1 || !.k2 /*construct the next Fibonacci word. */
end /*k*/ /* [↑] generate a " " */
return !.x /*return the Xth " " */</lang>
<br><br>(The output is shown <sup>1</sup>/<sub>8</sub> size.)
<b>
|