Fibonacci word/fractal: Difference between revisions

m
(→‎{{header|Perl 6}}: just use complex addition, duh)
 
(86 intermediate revisions by 33 users not shown)
Line 1:
{{task|Fractals}}
[[File:Fib_word_fractal.gif|613px||right]]
 
The [[Fibonacci word]] may be represented as a fractal as described [http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf here]:
<br><br><small>(Clicking on the above website &nbsp;</small> (hal.archives-ouvertes.fr) <small> &nbsp; will leave a cookie.)</small>
 
 
 
:For F_word<sub>m</sub> start with F_wordChar<sub>n=1</sub>
Line 9 ⟶ 14:
:next n and iterate until end of F_word
 
 
For this task create and display a fractal similar to [http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf Fig 1].
 
;Task:
Create and display a fractal similar to [http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf Fig 1].
<br><br><small>(Clicking on the above website &nbsp;</small> (hal.archives-ouvertes.fr) <small> &nbsp; will leave a cookie.)</small>
<br><br>
 
=={{header|AutoHotkey}}==
Prints F_Word<sub>30</sub> currently. Segment length and F_Word<sub>n</sub> can be adjusted.
{{libheader|GDIP}}Also see the [http://www.autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/ Gdip examples].
<langsyntaxhighlight AutoHotkeylang="autohotkey">#NoEnv
SetBatchLines, -1
p := 0.3 ; Segment length (pixels)
Line 88 ⟶ 98:
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp</langsyntaxhighlight>
 
=={{header|C}}==
Writes an EPS file that has the 26th fractal. This is probably cheating.
<syntaxhighlight lang="c">#include <stdio.h>
 
int main(void)
{
puts( "%!PS-Adobe-3.0 EPSF\n"
"%%BoundingBox: -10 -10 400 565\n"
"/a{0 0 moveto 0 .4 translate 0 0 lineto stroke -1 1 scale}def\n"
"/b{a 90 rotate}def");
 
char i;
for (i = 'c'; i <= 'z'; i++)
printf("/%c{%c %c}def\n", i, i-1, i-2);
 
puts("0 setlinewidth z showpage\n%%EOF");
 
return 0;
}</syntaxhighlight>
 
=={{header|C++}}==
 
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 261 ⟶ 291:
return system( "pause" );
}
</syntaxhighlight>
</lang>
 
=={{header|D}}==
This uses the turtle module from the Dragon Curve Task, and the module from the Grayscale Image task.
{{trans|Python}}
<langsyntaxhighlight lang="d">import std.range, grayscale_image, turtle;
 
void drawFibonacci(Color)(Image!Color img, ref Turtle t,
Line 287 ⟶ 317:
img.drawFibonacci(t, w, 1);
img.savePGM("fibonacci_word_fractal.pgm");
}</langsyntaxhighlight>
It prints the level 25 word as the Python entry.
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| Vcl.Graphics}}
<syntaxhighlight lang="delphi">
program Fibonacci_word;
 
{$APPTYPE CONSOLE}
{$R *.res}
 
uses
System.SysUtils,
Vcl.Graphics;
 
function GetWordFractal(n: Integer): string;
var
f1, f2, tmp: string;
i: Integer;
begin
case n of
0:
Result := '';
1:
Result := '1';
else
begin
f1 := '1';
f2 := '0';
 
for i := n - 2 downto 1 do
begin
tmp := f2;
f2 := f2 + f1;
f1 := tmp;
end;
 
Result := f2;
end;
end;
end;
 
procedure DrawWordFractal(n: Integer; g: TCanvas; x, y, dx, dy: integer);
var
i, tx: Integer;
wordFractal: string;
begin
wordFractal := GetWordFractal(n);
with g do
begin
Brush.Color := clWhite;
FillRect(ClipRect);
Pen.Color := clBlack;
pen.Width := 1;
MoveTo(x, y);
end;
for i := 1 to wordFractal.Length do
begin
g.LineTo(x + dx, y + dy);
inc(x, dx);
inc(y, dy);
if wordFractal[i] = '0' then
begin
tx := dx;
if Odd(i) then
begin
dx := dy;
dy := -tx;
end
else
begin
dx := -dy;
dy := tx;
end;
end;
end;
end;
 
function WordFractal2Bitmap(n, x, y, width, height: Integer): TBitmap;
begin
Result := TBitmap.Create;
Result.SetSize(width, height);
DrawWordFractal(n, Result.Canvas, x, height - y, 1, 0);
end;
 
begin
with WordFractal2Bitmap(23, 20, 20, 450, 620) do
begin
SaveToFile('WordFractal.bmp');
Free;
end;
end.
 
</syntaxhighlight>
=={{header|Elixir}}==
{{trans|Ruby}}
<syntaxhighlight lang="elixir">defmodule Fibonacci do
def fibonacci_word, do: Stream.unfold({"1","0"}, fn{a,b} -> {a, {b, b<>a}} end)
def word_fractal(n) do
word = fibonacci_word |> Enum.at(n)
walk(to_char_list(word), 1, 0, 0, 0, -1, %{{0,0}=>"S"})
|> print
end
defp walk([], _, _, _, _, _, map), do: map
defp walk([h|t], n, x, y, dx, dy, map) do
map2 = Map.put(map, {x+dx, y+dy}, (if dx==0, do: "|", else: "-"))
|> Map.put({x2=x+2*dx, y2=y+2*dy}, "+")
if h == ?0 do
if rem(n,2)==0, do: walk(t, n+1, x2, y2, dy, -dx, map2),
else: walk(t, n+1, x2, y2, -dy, dx, map2)
else
walk(t, n+1, x2, y2, dx, dy, map2)
end
end
defp print(map) do
xkeys = Map.keys(map) |> Enum.map(fn {x,_} -> x end)
{xmin, xmax} = Enum.min_max(xkeys)
ykeys = Map.keys(map) |> Enum.map(fn {_,y} -> y end)
{ymin, ymax} = Enum.min_max(ykeys)
Enum.each(ymin..ymax, fn y ->
IO.puts Enum.map(xmin..xmax, fn x -> Map.get(map, {x,y}, " ") end)
end)
end
end
 
Fibonacci.word_fractal(16)</syntaxhighlight>
Output is same as Ruby.
 
=={{header|F_Sharp|F#}}==
<p>We output an SVG or rather an HTML with an embedded SVG</p>
<p>Points to note:</p>
<ul>
<li>Rather than using the "usual" Fibonacci catamorphismen <syntaxhighlight lang="fsharp">Seq.unfold(fun (f1, f2) -> Some(f1, (f2, f2+f1))) ("1", "0")</syntaxhighlight> we use the morphism &sigma;: 0 &rarr; 01, 1 &rarr; 0, starting with a single 1, described in the referenced PDF in the task description.</li>
<li>The outer dimension of the SVG is computed. For a simplification we compute bounding boxes for fractals with number 3*k+2 only. These are &cap; formed or &sup; formed. For 3*k and 3*k+1 fractals the bounding box for the next 3*k+2 fractal is taken. (c/f PDF; Theorem 3, Theorem 4)</li>
</ul>
<syntaxhighlight lang="fsharp">let sigma s = seq {
for c in s do if c = '1' then yield '0' else yield '0'; yield '1'
}
let rec fibwordIterator s = seq { yield s; yield! fibwordIterator (sigma s) }
 
let goto (x, y) (dx, dy) c n =
let (dx', dy') =
if c = '0' then
match (dx, dy), n with
| (1,0),0 -> (0,1) | (1,0),1 -> (0,-1)
| (0,1),0 -> (-1,0) | (0,1),1 -> (1,0)
| (-1,0),0 -> (0,-1)| (-1,0),1 -> (0,1)
| (0,-1),0 -> (1,0) | (0,-1),1 -> (-1,0)
| _ -> failwith "not possible (c=0)"
else
(dx, dy)
(x+dx, y+dy), (dx', dy')
 
// How much longer a line is, compared to its thickness:
let factor = 2
 
let rec draw (x, y) (dx, dy) n = function
| [] -> ()
| z::zs ->
printf "%d,%d " (factor*(x+dx)) (factor*(y+dy))
let (xyd, d') = goto (x, y) (dx, dy) z n
draw xyd d' (n^^^1) zs
 
// Seq of (width,height). n-th (n>=0) pair is for fibword fractal f(3*n+2)
let wh = Seq.unfold (fun ((w1,h1,n),(w2,h2)) ->
Some((if n=0 then (w1,h1) else (h1,w1)), ((w2,h2,n^^^1),(2*w2+w1,w2+h2)))) ((1,0,1),(3,1))
 
[<EntryPoint>]
let main argv =
let n = (if argv.Length > 0 then int (System.UInt16.Parse(argv.[0])) else 23)
let (width,height) = Seq.head <| Seq.skip (n/3) wh
let fibWord = Seq.toList (Seq.item (n-1) <| fibwordIterator ['1'])
let (viewboxWidth, viewboxHeight) = ((factor*(width+1)), (factor*(height+1)))
printf """<!DOCTYPE html>
<html><body><svg height="100%%" width="100%%" viewbox="0 0 %d %d">
<polyline points="0,0 """ viewboxWidth viewboxHeight
draw (0,0) (0,1) 1 <| Seq.toList fibWord
printf """" style="fill:white;stroke:red;stroke-width:1" transform="matrix(1,0,0,-1,1,%d)"/>
Sorry, your browser does not support inline SVG.
</svg></body></html>""" (viewboxHeight-1)
0</syntaxhighlight>
{{out}}
<p>Since file upload to the Wiki is not possible, the raw output for F<sub>11</sub> is given:</p>
<pre style="white-space:pre-wrap"><!DOCTYPE html>
<html><body><svg height="100%" width="100%" viewbox="0 0 36 24">
<polyline points="0,0 0,2 2,2 4,2 4,0 6,0 8,0 8,2 8,4 6,4 6,6 6,8 8,8 8,10 8,12 6,12 4,12 4,10 2,10 0,10 0,12 0,14 2,14 2,16 2,18 0,18 0,20 0,22 2,22 4,22 4,20 6,20 8,20 8,22 10,22 12,22 12,20 12,18 10,18 10,16 10,14 12,14 14,14 14,16 16,16 18,16 18,14 20,14 22,14 22,16 22,18 20,18 20,20 20,22 22,22 24,22 24,20 26,20 28,20 28,22 30,22 32,22 32,20 32,18 30,18 30,16 30,14 32,14 32,12 32,10 30,10 28,10 28,12 26,12 24,12 24,10 24,8 26,8 26,6 26,4 24,4 24,2 24,0 26,0 28,0 28,2 30,2 32,2 32,0 34,0 " style="fill:white;stroke:red;stroke-width:1" transform="matrix(1,0,0,-1,1,23)"/>
Sorry, your browser does not support inline SVG.
</svg></body></html></pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: accessors arrays combinators fry images images.loader
kernel literals make match math math.vectors pair-rocket
sequences ;
FROM: fry => '[ _ ;
IN: rosetta-code.fibonacci-word-fractal
 
! === Turtle code ==============================================
 
TUPLE: turtle heading loc ;
C: <turtle> turtle
 
: forward ( turtle -- turtle' )
dup heading>> [ v+ ] curry change-loc ;
MATCH-VARS: ?a ;
 
CONSTANT: left { { 0 ?a } => [ ?a 0 ] { ?a 0 } => [ 0 ?a neg ] }
CONSTANT: right { { 0 ?a } => [ ?a neg 0 ] { ?a 0 } => [ 0 ?a ] }
 
: turn ( turtle left/right -- turtle' )
[ dup heading>> ] dip match-cond 2array >>heading ; inline
 
! === Fib word =================================================
: fib-word ( n -- str )
{
1 => [ "1" ]
2 => [ "0" ]
[ [ 1 - fib-word ] [ 2 - fib-word ] bi append ]
} case ;
! === Fractal ==================================================
 
: fib-word-fractal ( n -- seq )
[
[ { 0 -1 } { 10 417 } dup , <turtle> ] dip fib-word
[
1 + -rot forward dup loc>> ,
-rot CHAR: 0 = [
even? [ left turn ] [ right turn ] if
] [ drop ] if drop
] with each-index
] { } make ;
! === Image ====================================================
 
CONSTANT: w 598
CONSTANT: h 428
 
: init-img-data ( -- seq )
w h * 4 * [ 255 ] B{ } replicate-as ;
 
: <fib-word-fractal-img> ( -- img )
<image>
${ w h } >>dim
BGRA >>component-order
ubyte-components >>component-type
init-img-data >>bitmap ;
: fract>img ( seq -- img' )
[ <fib-word-fractal-img> dup ] dip [
'[ B{ 33 33 33 255 } _ first2 ] dip set-pixel-at
] with each ;
: main ( -- )
23 fib-word-fractal fract>img "fib-word-fractal.png"
save-graphic-image ;
MAIN: main</syntaxhighlight>
{{out}} Similar to fig. 1 from the paper and the image at the top of this page.
 
=={{header|FreeBASIC}}==
On a Windows 32bit system F_word35 is the biggest that can be drawn.
<syntaxhighlight lang="freebasic">' version 23-06-2015
' compile with: fbc -s console "filename".bas
 
Dim As String fw1, fw2, fw3
Dim As Integer a, b, d , i, n , x, y, w, h
Dim As Any Ptr img_ptr, scr_ptr
 
' data for screen/buffer size
Data 1, 2, 3, 2, 2, 2, 2, 2, 7, 10, 8, 14
Dim As Integer s(38,2)
For i = 3 To 9
Read s(i,1) : Read s(i,2)
Next
For i = 9 To 38 Step 6
s(i, 1) = s(i -1, 1) +2 : s(i, 2) = s(i -1, 1) + s(i -1, 2)
s(i +1, 1) = s(i, 2) +2 : s(i +1, 2) = s(i, 2)
s(i +2, 1) = s(i, 1) + s(i, 2) : s(i +2, 2) = s(i, 2)
s(i +3, 1) = s(i +1, 1 ) + s(i +2, 1) : s(i +3, 2) = s(i ,2)
s(i +4, 1) = s(i +3, 1) : s(i +4, 2) = s(i +3, 1) + 2
s(i +5, 1) = s(i +3, 1) : s(i +5, 2) = s(i +3, 2) + s(i +4, 2) +2
Next
 
' we need to set screen in order to create image buffer in memory
Screen 21
scr_ptr = ScreenPtr()
If (scr_ptr = 0) Then
Print "Error: graphics screen not initialized."
Sleep
End -1
End If
 
Do
Cls
Do
 
Print
Print "For wich n do you want the Fibonacci Word fractal (3 to 35)."
While Inkey <> "" : fw1 = Inkey : Wend ' empty keyboard buffer
Input "Enter or a value smaller then 3 to stop: "; n
If n < 3 Then
Print : Print "Stopping."
Sleep 3000,1
End
EndIf
If n > 35 then
Print : Print "Fractal is to big, unable to create it."
Sleep 3000,1
Continue Do
End If
Loop Until n < 36
 
fw1 = "1" : fw2 = "0" ' construct the string
For i = 3 To n
fw3 = fw2 + fw1
Swap fw1, fw2 ' swap pointers of fw1 and fw2
Swap fw2, fw3 ' swap pointers of fw2 and fw3
Next
fw1 = "" : fw3 = "" ' free up memory
 
w = s(n, 1) +1 : h = s(n, 2) +1
' allocate memory for a buffer to hold the image
' use 8 bits to hold the color
img_ptr = ImageCreate(w,h,0,8)
If img_ptr = 0 Then ' check if we have created a image buffer
Print "Failed to create image."
Sleep
End -1
End If
 
x = 0: y = h -1 : d = 1 ' set starting point and direction flag
PSet img_ptr, (x, y) ' set start point
For a = 1 To Len(fw2)
Select Case As Const d
Case 0
x = x + 2
Case 1
y = y - 2
Case 2
x = x - 2
Case 3
y = y + 2
End Select
Line img_ptr, -(x, y)
b = fw2[a-1] - Asc("0")
If b = 0 Then
If (a And 1) Then
d = d + 3 ' a = odd
Else
d = d + 1 ' a = even
End If
d = d And 3
End If
Next
 
If n < 24 Then ' size is smaller then screen dispay fractal
Cls
Put (5, 5),img_ptr, PSet
Else
Print
Print "Fractal is to big for display."
End If
' saves fractal as bmp file (8 bit palette)
If n > 23 Then h = 80
Draw String (0, h +16), "saving fractal as fibword" + Str(n) + ".bmp."
BSave "F_Word" + Str(n) + ".bmp", img_ptr
Draw String (0, h +32), "Hit any key to continue."
Sleep
ImageDestroy(img_ptr) ' free memory holding the image
Loop</syntaxhighlight>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_fractalView
end enum
 
local fn BuildWindow
window _window, @"Rosetta Code Fibonacci Word/Fractal", ( 0, 0, 640, 480 )
imageview _fractalView,,, ( 20, 20, 600, 440 ), NSImageScaleAxesIndependently, NSImageAlignCenter, NSImageFrameGrayBezel, _window
ViewSetWantsLayer( _fractalView, YES )
CALayerRef layer = fn ViewLayer( _fractalView )
CALayerSetBackgroundColor( layer, fn ColorWhite )
ViewRotateByAngle( _fractalView, 90 )
end fn
 
local fn CreateEPSFile as CFDataRef
NSUInteger i
CFStringRef header = @"%%!PS-Adobe-3.0 EPSF\n%%%%BoundingBox: 0 0 400 565\n¬
/a{0 0 moveto 0 .4 translate 0 0 lineto stroke -1 1 scale}def\n/b{a 90 rotate}def"
CFMutableStringRef mutStr = fn MutableStringWithString( header )
_cASCII = 99 : _zASCII = 122
for i = _cASCII to _zASCII
MutableStringAppendString( mutStr, fn StringWithFormat( @"/%c{%c %c}def\n", i, i - 1, i - 2 ) )
next
MutableStringAppendString( mutStr, @"0 setlinewidth z showpage\n%%EOF" )
CFDataRef epsData = fn StringData( mutStr, NSASCIIStringEncoding )
end fn = epsData
 
void local fn EPSDataToImageToView
CFDataRef epsData = fn CreateEPSFile
ImageRef epsImage = fn ImageWithData( epsData )
CGSize size = fn CGSizeMake( 405, 560 )
ImageRef cropImage = fn ImageWithSize( size )
ImageLockFocus( cropImage )
CGRect r = fn CGRectMake( 0, 0, size.width, size.height )
ImageDrawInRectFromRect( epsImage, r, fn CGRectMake( 0, 0, size.width, size.height ), NSCompositeCopy, 1.0 )
ImageUnlockFocus( cropImage )
ImageViewSetImage( _fractalView, cropImage )
end fn
 
fn BuildWindow
fn EPSDataToImageToView
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Fibonacci Word Fractal2.png]]
 
 
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Fibonacci_word}}
 
'''Solution'''
 
The following function generate the Fibonacci word of a given order:
 
[[File:Fōrmulæ - Fibonacci word 01.png]]
 
'''Drawing a Fibonacci word fractal'''
 
It can be done using an [[wp:L-system|L-system]]. There are generic functions written in Fōrmulæ to compute an L-system in the page [[L-system#Fōrmulæ | L-system]].
 
The program to draw a Fibonacci word fractal is:
 
[[File:Fōrmulæ - Fibonacci word 11.png]]
 
[[File:Fōrmulæ - Fibonacci word 12.png]]
 
=={{header|Go}}==
{{libheader|Go Graphics}}
{{trans|Kotlin}}
<syntaxhighlight lang="go">package main
 
import (
"github.com/fogleman/gg"
"strings"
)
 
func wordFractal(i int) string {
if i < 2 {
if i == 1 {
return "1"
}
return ""
}
var f1 strings.Builder
f1.WriteString("1")
var f2 strings.Builder
f2.WriteString("0")
for j := i - 2; j >= 1; j-- {
tmp := f2.String()
f2.WriteString(f1.String())
f1.Reset()
f1.WriteString(tmp)
}
return f2.String()
}
 
func draw(dc *gg.Context, x, y, dx, dy float64, wf string) {
for i, c := range wf {
dc.DrawLine(x, y, x+dx, y+dy)
x += dx
y += dy
if c == '0' {
tx := dx
dx = dy
if i%2 == 0 {
dx = -dy
}
dy = -tx
if i%2 == 0 {
dy = tx
}
}
}
}
 
func main() {
dc := gg.NewContext(450, 620)
dc.SetRGB(0, 0, 0)
dc.Clear()
wf := wordFractal(23)
draw(dc, 20, 20, 1, 0, wf)
dc.SetRGB(0, 1, 0)
dc.SetLineWidth(1)
dc.Stroke()
dc.SavePNG("fib_wordfractal.png")
}</syntaxhighlight>
 
{{out}}
<pre>
Image similar to Java entry except green on black background.
</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 295 ⟶ 837:
a single pixel.
 
<langsyntaxhighlight lang="unicon">global width, height
 
procedure main(A)
Line 351 ⟶ 893:
DrawLine(p.x,p.y, p1.x,p1.y)
return p1
end</langsyntaxhighlight>
 
=={{header|Haskell}}==
 
<syntaxhighlight lang="haskell">import Data.List (unfoldr)
import Data.Bool (bool)
import Data.Semigroup (Sum(..), Min(..), Max(..))
import System.IO (writeFile)
 
fibonacciWord :: a -> a -> [[a]]
fibonacciWord a b = unfoldr (\(a,b) -> Just (a, (b, a <> b))) ([a], [b])
 
toPath :: [Bool] -> ((Min Int, Max Int, Min Int, Max Int), String)
toPath = foldMap (\p -> (box p, point p)) .
scanl (<>) mempty .
scanl (\dir (turn, s) -> bool dir (turn dir) s) (1, 0) .
zip (cycle [left, right])
where
box (Sum x, Sum y) = (Min x, Max x, Min y, Max y)
point (Sum x, Sum y) = show x ++ "," ++ show y ++ " "
left (x,y) = (-y, x)
right (x,y) = (y, -x)
 
toSVG :: [Bool] -> String
toSVG w =
let ((Min x1, Max x2, Min y1, Max y2), path) = toPath w
in unwords
[ "<svg xmlns='http://www.w3.org/2000/svg'"
, "width='500' height='500'"
, "stroke='black' fill='none' strokeWidth='2'"
, "viewBox='" ++ unwords (show <$> [x1,y1,x2-x1,y2-y1]) ++ "'>"
, "<polyline points='" ++ path ++ "'/>"
, "</svg>"]
 
main = writeFile "test.html" $ toSVG $ fibonacciWord True False !! 21</syntaxhighlight>
 
=={{header|J}}==
Line 357 ⟶ 933:
Plotting the fractal as a parametric equation, this looks reasonably nice:
 
<langsyntaxhighlight Jlang="j">require 'plot'
plot }:+/\ 0,*/\(^~ 0j_1 0j1 $~ #)'0'=_1{::F_Words 20</langsyntaxhighlight>
 
Note that we need the definition of F_Words from the [[Fibonacci_word#J|Fibonacci word]] page:
 
<langsyntaxhighlight Jlang="j">F_Words=: (,<@;@:{~&_1 _2)@]^:(2-~[)&('1';'0')</langsyntaxhighlight>
 
However, image uploads are currently disabled, and rendering images of this sort as wikitext gets bulky.
Line 368 ⟶ 944:
Instead, I'll just describe the algorithm:
 
This draws a discrete parametric curve. Right turn is 0j_1, left turn is 0j1 (negative and positive square roots of negative 1), straight ahead is 1. So: build a list of alternating 0j_1 and 0j1 and raise them to the first power for the 0s in the fibonacci word list and raise them to the 0th power for the 1s in that list. Then compute the running product,sum shift aof 0 ontofollowed the front ofby the list ofrunning products andof computethat the running sumlist. (Of course, this would translate to a rather simple loop, also, once you see the pattern.)
 
=={{header|Java}}==
[[File:fib_word_fractal_java.gif|300px|thumb|right]]
{{works with|Java|8}}
<syntaxhighlight lang="java">import java.awt.*;
import javax.swing.*;
 
public class FibonacciWordFractal extends JPanel {
String wordFractal;
 
FibonacciWordFractal(int n) {
setPreferredSize(new Dimension(450, 620));
setBackground(Color.white);
wordFractal = wordFractal(n);
}
 
public String wordFractal(int n) {
if (n < 2)
return n == 1 ? "1" : "";
 
// we should really reserve fib n space here
StringBuilder f1 = new StringBuilder("1");
StringBuilder f2 = new StringBuilder("0");
 
for (n = n - 2; n > 0; n--) {
String tmp = f2.toString();
f2.append(f1);
 
f1.setLength(0);
f1.append(tmp);
}
 
return f2.toString();
}
 
void drawWordFractal(Graphics2D g, int x, int y, int dx, int dy) {
for (int n = 0; n < wordFractal.length(); n++) {
g.drawLine(x, y, x + dx, y + dy);
x += dx;
y += dy;
if (wordFractal.charAt(n) == '0') {
int tx = dx;
dx = (n % 2 == 0) ? -dy : dy;
dy = (n % 2 == 0) ? tx : -tx;
}
}
}
 
@Override
public void paintComponent(Graphics gg) {
super.paintComponent(gg);
Graphics2D g = (Graphics2D) gg;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
 
drawWordFractal(g, 20, 20, 1, 0);
}
 
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Fibonacci Word Fractal");
f.setResizable(false);
f.add(new FibonacciWordFractal(23), BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
});
}
}</syntaxhighlight>
 
=={{header|JavaScript}}==
{{trans|PARI/GP}}
 
[[File:FiboWFractal2.png|200px|right|thumb|Output FiboWFractal2.png]]
[[File:FiboWFractal1.png|200px|right|thumb|Output FiboWFractal1.png]]
 
<syntaxhighlight lang="javascript">
// Plot Fibonacci word/fractal
// FiboWFractal.js - 6/27/16 aev
function pFibowFractal(n,len,canvasId,color) {
// DCLs
var canvas = document.getElementById(canvasId);
var ctx = canvas.getContext("2d");
var w = canvas.width; var h = canvas.height;
var fwv,fwe,fn,tx,x=10,y=10,dx=len,dy=0,nr;
// Cleaning canvas, setting plotting color, etc
ctx.fillStyle="white"; ctx.fillRect(0,0,w,h);
ctx.beginPath();
ctx.moveTo(x,y);
fwv=fibword(n); fn=fwv.length;
// MAIN LOOP
for(var i=0; i<fn; i++) {
ctx.lineTo(x+dx,y+dy); fwe=fwv[i];
if(fwe=="0") {tx=dx; nr=i%2;
if(nr==0) {dx=-dy;dy=tx} else {dx=dy;dy=-tx}};
x+=dx; y+=dy;
}//fend i
ctx.strokeStyle = color; ctx.stroke();
}//func end
// Create and return Fibonacci word
function fibword(n) {
var f1="1",f2="0",fw,fwn,n2,i;
if (n<5) {n=5}; n2=n+2;
for (i=0; i<n2; i++) {fw=f2+f1;f1=f2;f2=fw};
return(fw)
}
</syntaxhighlight>
 
'''Executing:'''
<syntaxhighlight lang="html">
<!-- FiboWFractal2.html -->
<html>
<head>
<title>Fibonacci word/fractal</title>
<script src="FiboWFractal.js"></script>
</head>
<body onload="pFibowFractal(31,2,'canvid','red')">
<h3>Fibonacci word/fractal: n=31, len=2</h3>
<canvas id="canvid" width="850" height="1150" style="border: 2px inset;"></canvas>
</body>
</html>
 
<!-- FiboWFractal1.html -->
<html>
<head>
<title>Fibonacci word/fractal</title>
<script src="FiboWFractal.js"></script>
</head>
<body onload="pFibowFractal(31,1,'canvid','navy')">
<h3>Fibonacci word/fractal: n=31, len=1</h3>
<canvas id="canvid" width="1400" height="1030" style="border: 2px inset;"></canvas>
</body>
</html>
</syntaxhighlight>
 
{{Output}}
 
<pre>
Page with FiboWFractal2.png
Page with FiboWFractal1.png
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq.'''
 
The SVG output is suitable for viewing in a browser.
<syntaxhighlight lang=jq>
def max(s): reduce s as $x (-infinite; if $x > . then $x else . end);
def min(s): reduce s as $x ( infinite; if $x < . then $x else . end);
 
# An unbounded stream
def fibonacci_words:
"1",
(["0","1"] | recurse( [add, .[0]]) | .[0]);
 
def turnLeft:
{"R": "U",
"U": "L",
"L": "D",
"D": "R"};
 
def turnRight:
{"R": "D",
"D": "L",
"L": "U",
"U": "R"};
 
# Input: the remaining Fibonacci word
# $n should initially be 1 and represents
# 1 plus the count of the letters already processed.
#
# Emit a stream of single-letter directions ("1" for forward),
# namely, if current char is 0
# - turn left if $n is even
# - turn right if $n is odd
def directions($n):
if length == 0 then empty
else .[0:1] as $c
| (if $c == "0"
then if $n % 2 == 0 then "L" else "R" end
else "1"
end),
(.[1:] | directions($n+1))
end;
 
# $current is the direction in which we are currently pointing.
# output: the direction in which the next step should be taken
def next_step($current; $turn):
if $turn == "1" then $current
elif $turn == "L" then turnLeft[$current]
elif $turn == "R" then turnRight[$current]
else error
end;
 
# input: a Fibonacci word
# output: a stream of directions for turning, or "1" for not turning,
# i.e. a stream of: U, D, L, R, or 1
# Initially, we are facing R
def steps:
foreach directions(1) as $turn ("R";
next_step(.; $turn) );
# output a stream of [x,y] co-ordinates corresponding to the specified
# stream of steps of the given size.
# So we could for example call: points( nth(5; fibonacci_words) | steps; $size)
def points(steps; $size):
foreach steps as $step ([0,0];
. as [$x, $y]
| if $step == "R" then [$x + $size, $y]
elif $step == "D" then [$x, $y + $size]
elif $step == "L" then [$x - $size, $y]
elif $step == "U" then [$x, $y - $size]
else error
end );
 
# svg header boilerplate
# viewBox = '<min-x> <min-y> <width> <height>'
def svg($minX; $minY; $width; $height):
"<?xml version='1.0' standalone='no'?>",
"<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>",
"<svg viewBox='\($minX - 10) \($minY - 10) \($width + 20) \($height + 20)' version='1.1' xmlns='http://www.w3.org/2000/svg'>";
 
# input: array of [x,y] co-ordinates
# output: "<polyline .... />"
def polyline:
{a:1, b:1} as $p
| "<polyline points='\(map(join(","))|join(" "))'",
" style='fill:none; stroke:black; stroke-width:1' transform='translate(\($p.a), \($p.b))' />";
 
# Output the svg for the $n-th Fibonacci word counting from 0
def fibonacci_word_svg($n):
[points( nth($n; fibonacci_words) | steps; 10)]
| min( .[] | .[0]) as $minx
| max( .[] | .[0]) as $maxx
| min( .[] | .[1]) as $miny
| max( .[] | .[1]) as $maxy
| (($maxx-$minx)|length) as $width
| (($maxy-$miny)|length) as $height
| svg( $minx; $miny; $width; $height),
polyline,
"</svg>" ;
fibonacci_word_svg(22) # the Rust entry uses 22
</syntaxhighlight>
{{output}}
Essentially as for [[#Rust|Rust]] - [[Media:Fibword_fractal_rust.svg]]
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<syntaxhighlight lang="julia">using Luxor, Colors
 
function fwfractal!(word::AbstractString, t::Turtle)
left = 90
right = -90
for (n, c) in enumerate(word)
Forward(t)
if c == '0'
Turn(t, ifelse(iseven(n), left, right))
end
end
return t
end
 
word = last(fiboword(25))
 
touch("data/fibonaccifractal.png")
Drawing(800, 800, "data/fibonaccifractal.png");
background(colorant"white")
t = Turtle(100, 300)
fwfractal!(word, t)
finish()
preview()</syntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.*
import javax.swing.*
 
class FibonacciWordFractal(n: Int) : JPanel() {
private val wordFractal: String
init {
preferredSize = Dimension(450, 620)
background = Color.black
wordFractal = wordFractal(n)
}
 
fun wordFractal(i: Int): String {
if (i < 2) return if (i == 1) "1" else ""
val f1 = StringBuilder("1")
val f2 = StringBuilder("0")
for (j in i - 2 downTo 1) {
val tmp = f2.toString()
f2.append(f1)
f1.setLength(0)
f1.append(tmp)
}
return f2.toString()
}
 
private fun drawWordFractal(g: Graphics2D, x: Int, y: Int, dx: Int, dy: Int) {
var x2 = x
var y2 = y
var dx2 = dx
var dy2 = dy
for (i in 0 until wordFractal.length) {
g.drawLine(x2, y2, x2 + dx2, y2 + dy2)
x2 += dx2
y2 += dy2
if (wordFractal[i] == '0') {
val tx = dx2
dx2 = if (i % 2 == 0) -dy2 else dy2
dy2 = if (i % 2 == 0) tx else -tx
}
}
}
 
override fun paintComponent(gg: Graphics) {
super.paintComponent(gg)
val g = gg as Graphics2D
g.color = Color.green
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON)
drawWordFractal(g, 20, 20, 1, 0)
}
}
 
fun main(args: Array<String>) {
SwingUtilities.invokeLater {
val f = JFrame()
with(f) {
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
title = "Fibonacci Word Fractal"
isResizable = false
add(FibonacciWordFractal(23), BorderLayout.CENTER)
pack()
setLocationRelativeTo(null)
isVisible = true
}
}
}</syntaxhighlight>
 
=={{header|Logo}}==
Line 374 ⟶ 1,299:
 
{{works with|UCB Logo}}
<langsyntaxhighlight Logolang="logo">; Return the low 1-bits of :n
; For example if n = binary 10110111 = 183
; then return binary 111 = 7
Line 402 ⟶ 1,327:
 
setheading 0 ; initial line North
fibonacci.word.fractal 377</langsyntaxhighlight>
 
=={{header|Lua}}==
===L&Ouml;VE===
Needs L&Ouml;VE 2D Engine
<syntaxhighlight lang="lua">
RIGHT, LEFT, UP, DOWN = 1, 2, 4, 8
function drawFractals( w )
love.graphics.setCanvas( canvas )
love.graphics.clear()
love.graphics.setColor( 255, 255, 255 )
local dir, facing, lineLen, px, py, c = RIGHT, UP, 1, 10, love.graphics.getHeight() - 20, 1
local x, y = 0, -lineLen
local pts = {}
table.insert( pts, px + .5 ); table.insert( pts, py + .5 )
for i = 1, #w do
px = px + x; table.insert( pts, px + .5 )
py = py + y; table.insert( pts, py + .5 )
if w:sub( i, i ) == "0" then
if c % 2 == 1 then dir = RIGHT else dir = LEFT end
if facing == UP then
if dir == RIGHT then x = lineLen; facing = RIGHT
else x = -lineLen; facing = LEFT end; y = 0
elseif facing == RIGHT then
if dir == RIGHT then y = lineLen; facing = DOWN
else y = -lineLen; facing = UP end; x = 0
elseif facing == DOWN then
if dir == RIGHT then x = -lineLen; facing = LEFT
else x = lineLen; facing = RIGHT end; y = 0
elseif facing == LEFT then
if dir == RIGHT then y = -lineLen; facing = UP
else y = lineLen; facing = DOWN end; x = 0
end
end
c = c + 1
end
love.graphics.line( pts )
love.graphics.setCanvas()
end
function createWord( wordLen )
local a, b, w = "1", "0"
repeat
w = b .. a; a = b; b = w; wordLen = wordLen - 1
until wordLen == 0
return w
end
function love.load()
wid, hei = love.graphics.getWidth(), love.graphics.getHeight()
canvas = love.graphics.newCanvas( wid, hei )
drawFractals( createWord( 21 ) )
end
function love.draw()
love.graphics.draw( canvas )
end
</syntaxhighlight>
===ASCII===
Uses the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending..
<syntaxhighlight lang="lua">function Bitmap:fiboword(n)
local function fw(n) return n==1 and "1" or n==2 and "0" or fw(n-1)..fw(n-2) end
local word, x, y, dx, dy = fw(n), 0, self.height-1, 0, -1
for i = 1, #word do
self:set(x, y, "+")
x, y = x+dx, y+dy
self:set(x, y, dx==0 and "|" or "-")
x, y = x+dx, y+dy
if word:sub(i,i)=="0" then
dx, dy = i%2==0 and dy or -dy, i%2==0 and -dx or dx
end
end
end
 
function Bitmap:render()
for y = 1, self.height do
print(table.concat(self.pixels[y]))
end
end
 
bitmap = Bitmap(58,82)
bitmap:clear(" ")
bitmap:fiboword(14)
bitmap:render()</syntaxhighlight>
{{out}}
<pre style="font-size:50%">|
+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+
| | | | | | | | | | |
+-+-+ + + +-+-+ + + +-+-+ +
| | | | |
+-+ +-+ +-+ +-+ +-+
| | | | |
+ + + +-+-+ + +
| | | | | | |
+-+ +-+ +-+-+ +-+-+ +-+
| | |
+-+-+ + + +-+-+ +-+-+ +
| | | | | | | | |
+ +-+-+ +-+-+ + + +-+-+
| | |
+-+ +-+-+ +-+-+ +-+ +-+
| | | | | | |
+ + +-+-+ + + +
| | | | |
+-+ +-+ +-+ +-+ +-+
| | | | |
+ +-+-+ + + +-+-+ + + +-+-+
| | | | | | | | | | |
+-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +
|
+-+-+ +-+-+ +-+
| | | | |
+ +-+-+ + +
| | |
+-+ +-+ +-+
| | |
+ + +-+-+ +
| | | | |
+-+ +-+-+ +-+-+
|
+ +-+-+
| | |
+-+-+ +
|
+-+
|
+
|
+-+
|
+-+-+ +
| | |
+ +-+-+
|
+-+ +-+-+ +-+-+
| | | | |
+ + +-+-+ +
| | |
+-+ +-+ +-+
| | |
+ +-+-+ + +
| | | | |
+-+-+ +-+-+ +-+
|
+-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +
| | | | | | | | | | |
+ +-+-+ + + +-+-+ + + +-+-+
| | | | |
+-+ +-+ +-+ +-+ +-+
| | | | |
+ + +-+-+ + + +
| | | | | | |
+-+ +-+-+ +-+-+ +-+ +-+
| | |
+ +-+-+ +-+-+ + + +-+-+
| | | | | | | | |
+-+-+ + + +-+-+ +-+-+ +
| | |
+-+ +-+ +-+-+ +-+-+ +-+
| | | | | | |
+ + + +-+-+ + +
| | | | |
+-+ +-+ +-+ +-+ +-+
| | | | |
+-+-+ + + +-+-+ + + +-+-+ +
| | | | | | | | | | |
+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
 
<syntaxhighlight lang="mathematica">(*note, this usage of Module allows us to memoize FibonacciWord
without exposing it to the global scope*)
Module[{FibonacciWord, step},
FibonacciWord[1] = "1";
FibonacciWord[2] = "0";
FibonacciWord[n_Integer?(# > 2 &)] :=
(FibonacciWord[n] = FibonacciWord[n - 1] <> FibonacciWord[n - 2]);
step["0", {_?EvenQ}] = N@RotationTransform[Pi/2];
step["0", {_?OddQ}] = N@RotationTransform[-Pi/2];
step[___] = Identity;
FibonacciFractal[n_] := Module[{steps, dirs},
steps = MapIndexed[step, Characters[FibonacciWord[n]]];
dirs = ComposeList[steps, {0, 1}];
Graphics[Line[FoldList[Plus, {0, 0}, dirs]]]]];</syntaxhighlight>
 
=={{header|Nim}}==
{{libheader|imageman}}
<syntaxhighlight lang="nim">import imageman
 
const
Width = 1000
Height = 1000
LineColor = ColorRGBU [byte 64, 192, 96]
Output = "fibword.png"
 
 
proc fibword(n: int): string =
## Return the nth fibword.
var a = "1"
result = "0"
for _ in 1..n:
a = result & a
swap a, result
 
 
proc drawFractal(image: var Image; fw: string) =
# Draw the fractal.
var
x = 0
y = image.h - 1
dx = 1
dy = 0
 
for i, ch in fw:
let (nextx, nexty) = (x + dx, y + dy)
image.drawLine((x, y), (nextx, nexty), LineColor)
(x, y) = (nextx, nexty)
if ch == '0':
if (i and 1) == 0:
(dx, dy) = (dy, -dx)
else:
(dx, dy) = (-dy, dx)
 
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
var image = initImage[ColorRGBU](Width, Height)
image.fill(ColorRGBU [byte 0, 0, 0])
image.drawFractal(fibword(23))
 
# Save into a PNG file.
image.savePNG(Output, compression = 9)</syntaxhighlight>
 
=={{header|PARI/GP}}==
===Version #1.===
 
In this version only function plotfibofract() was translated from C++,
plus upgraded to plot different kind/size of Fibonacci word/fractals.
 
[[File:Fibofrac1.png|200px|right|thumb|Output Fibofrac1.png]]
[[File:Fibofrac2.png|200px|right|thumb|Output Fibofrac2.png]]
 
{{trans|C++}}
 
{{Works with|PARI/GP|2.7.4 and above}}
 
<syntaxhighlight lang="parigp">
\\ Fibonacci word/fractals
\\ 4/25/16 aev
fibword(n)={
my(f1="1",f2="0",fw,fwn,n2);
if(n<=4, n=5);n2=n-2;
for(i=1,n2, fw=Str(f2,f1); f1=f2;f2=fw;); fwn=#fw;
fw=Vecsmall(fw);
for(i=1,fwn,fw[i]-=48);
return(fw);
}
 
nextdir(n,d)={
my(dir=-1);
if(d==0, if(n%2==0, dir=0,dir=1)); \\0-left,1-right
return(dir);
}
 
plotfibofract(n,sz,len)={
my(fwv,fn,dr,px=10,py=420,x=0,y=-len,g2=0,
ttl="Fibonacci word/fractal: n=");
plotinit(0); plotcolor(0,6); \\green
plotscale(0, -sz,sz, -sz,sz);
plotmove(0, px,py);
fwv=fibword(n); fn=#fwv;
for(i=1,fn,
plotrline(0,x,y);
dr=nextdir(i,fwv[i]);
if(dr==-1, next);
\\up
if(g2==0, y=0; if(dr, x=len;g2=1, x=-len;g2=3); next);
\\right
if(g2==1, x=0; if(dr, y=len;g2=2, y=-len;g2=0); next);
\\down
if(g2==2, y=0; if(dr, x=-len;g2=3, x=len;g2=1); next);
\\left
if(g2==3, x=0; if(dr, y=-len;g2=0, y=len;g2=2); next);
);\\fend i
plotdraw([0,-sz,-sz]);
print(" *** ",ttl,n," sz=",sz," len=",len," fw-len=",fn);
 
}
 
{\\ Executing:
plotfibofract(11,430,20); \\ Fibofrac1.png
plotfibofract(21,430,2); \\ Fibofrac2.png
}
</syntaxhighlight>
 
{{Output}}
 
<pre>
> plotfibofract(11,430,20); \\ Fibofrac1.png
*** Fibonacci word/fractal: n=11 sz=430 len=20 fw-len=89
 
> plotfibofract(21,430,2); \\ Fibofrac2.png
*** Fibonacci word/fractal: n=21 sz=430 len=2 fw-len=10946
</pre>
 
===Version #2.===
In this version only function plotfibofract1() was translated from Java,
plus upgraded to plot different kind/size of Fibonacci word/fractals.
 
[[File:Fibofrac3.png|200px|right|thumb|Output Fibofrac3.png]]
[[File:Fibofrac4.png|200px|right|thumb|Output Fibofrac4.png]]
 
{{trans|Java}}
 
{{Works with|PARI/GP|2.7.4 and above}}
 
<syntaxhighlight lang="parigp">
\\ Fibonacci word/fractals 2nd version
\\ 4/26/16 aev
fibword(n)={
my(f1="1",f2="0",fw,fwn,n2); \\check n2 in v2 ADD it!!
if(n<=4, n=5); n2=n-2;
for(i=1,n2, fw=Str(f2,f1); f1=f2;f2=fw;); fwn=#fw;
fw=Vecsmall(fw);
for(i=1,fwn,fw[i]-=48);
return(fw);
}
 
plotfibofract1(n,sz,len)={
my(fwv,fn,dx=len,dy=0,nr,ttl="Fibonacci word/fractal, n=");
plotinit(0); plotcolor(0,5); \\red
plotscale(0, -sz,sz, -sz,sz); plotmove(0, 0,0);
fwv=fibword(n); fn=#fwv;
for(i=1,fn, plotrline(0,dx,dy);
if(fwv[i]==0, tx=dx; nr=i%2; if(!nr,dx=-dy;dy=tx, dx=dy;dy=-tx));
);\\fend i
plotdraw([0,0,0]);
print(" *** ",ttl,n," sz=",sz," len=",len," fw-len=",fn);
}
 
{\\ Executing:
plotfibofract1(17,500,6); \\ Fibofrac3.png
plotfibofract1(21,600,1); \\ Fibofrac4.png
}
</syntaxhighlight>
 
{{Output}}
 
<pre>
> plotfibofract1(17,500,6); \\ Fibofrac3.png
*** Fibonacci word/fractal: n=17 sz=500 len=6 fw-len=1597
 
> plotfibofract1(21,600,1); \\ Fibofrac4.png
*** Fibonacci word/fractal: n=21 sz=600 len=1 fw-len=10946
</pre>
 
=={{header|Perl}}==
Creates file fword.png containing the Fibonacci Fractal.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use GD;
Line 419 ⟶ 1,697:
 
my $size = 3000;
my $im = new GD::Image->new($size,$size);
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
Line 442 ⟶ 1,720:
print $out $im->png;
close $out;
</syntaxhighlight>
</lang>
 
=={{header|Perl=Using 6}}Tk===
This draws a segment at a time so you can watch it grow :)
<lang perl6>constant @fib-word = '1', '0', { $^b ~ $^a } ... *;
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Fibonacci_word
sub MAIN($m = 18, $scale = 2) {
use warnings;
(my %world){0}{0} = 1;
use Tk;
my $loc = 0+0i;
my $dir = i;
my $n = 1;
 
my @fword = ( 1, 0 );
for @fib-word[$m].comb {
push @fword, $fword[-1] . $fword[-2] for 1 .. 21;
when '0' {
#use Data::Dump 'dd'; dd@fword;
step;
if $n %% 2 { turn-left }
else { turn-right; }
}
$n++;
}
 
my $mw = MainWindow->new;
braille-graphics %world;
my $c = $mw->Canvas( -width => 1185, -height => 860,
)->pack;
$mw->Button(-text => 'Exit', -command => sub {$mw->destroy},
)->pack(-fill => 'x', -side => 'right');
$mw->Button(-text => 'Redraw', -command => sub {draw($fword[-1])},
)->pack(-fill => 'x', -side => 'right');
 
$mw->update;
draw($fword[-1]);
 
MainLoop;
-M $0 < 0 and exec $0;
 
sub step {draw
{
for ^$scale {
$c->delete('all');
$loc += $dir;
my $string = shift;
%world{$loc.im}{$loc.re} = 1;
my ($x, $y) = ($c->width - 20, $c->height - 20);
}
my ($dx, $dy) = (0, -2);
my $count = 0;
for my $ch ( split //, $string )
{
my ($nx, $ny) = ($x + $dx, $y + $dy);
$c->createLine($x, $y, $nx, $ny);
$mw->update;
($x, $y) = ($nx, $ny);
$count++;
$ch or ($dx, $dy) = $count % 2 ? ($dy, -$dx) : (-$dy, $dx);
}
}
</syntaxhighlight>
 
=={{header|Phix}}==
sub turn-left { $dir *= i; }
{{libheader|Phix/pGUI}}
sub turn-right { $dir *= -i; }
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/fibonaccifractal.htm here].
Output matches Fig 1 (at the top of the page)
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\FibonacciFractal.exw
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span>
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">drawFibonacci</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"1"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">word</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"0"</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">3</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">prev</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">word</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">&</span><span style="color: #000000;">prev</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">dx</span> <span style="color: #000000;">y</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">dy</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]==</span><span style="color: #008000;">'0'</span> <span style="color: #008080;">then</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)?{</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">}:{-</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*posx*/</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">/*posy*/</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasClear</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">drawFibonacci</span><span style="color: #0000FF;">(</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">23</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cdcanvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cddbuffer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_DBUFFER</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_GREEN</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=620x450"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetCallbacks</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">),</span>
<span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">)})</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`RESIZE=NO, TITLE="Fibonacci Fractal"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
=={{header|Processing}}==
Written in Processing ([http://www.processing.org Processing])
 
<syntaxhighlight lang="processing">
int n = 18;
String f1 = "1";
String f2 = "0";
String f3;
 
 
void setup(){
size(600,600);
background(255);
translate(10, 10);
createSeries();
}
 
void createSeries(){
sub braille-graphics (%a) {
my for($ylo,int $yhi,i=0; $xlo,i<n; $xhii++);{
forf3 %a.keys= -> $y {f2+f1;
$ylo min= +$y; $yhi maxf1 = +$yf2;
f2 = f3;
for %a{$y}.keys -> $x {
}
$xlo min= +$x; $xhi max= +$x;
drawFractal();
}
}
}
 
void drawFractal(){
for $ylo, $ylo + 4 ...^ * > $yhi -> \y {
char[] a = f3.toCharArray();
for $xlo, $xlo + 2 ...^ * > $xhi -> \x {
for(int i=0; i<a.length; i++){
my $cell = 0x2800;
$cell += 1 if %(a{y + [i]=='0}'){x + 0};
$cell += 2 if (i%a2==0){y + 1}{x + 0};
$cell += 4 if %a{y + rotate(PI/2}{x + 0});
}
$cell += 8 if %a{y + 0}{x + 1};
else{
$cell += 16 if %a{y + 1}{x + 1};
$cell += 32 if %a{y + rotate(-PI/2}{x + 1});
}
$cell += 64 if %a{y + 3}{x + 0};
$cell += 128 if %a{y + 3}{x + 1};
print chr($cell);
}
print "\n";
}
line(0,0,2,0);
}</lang>
translate(2,0);
{{out}}
}
<small><small><pre>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
}
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
</syntaxhighlight>
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡤⡄⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⠉⠁⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠉⠧⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⡭⡅⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⡭⡅⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⠉⠁⠀⠀⠉⠁⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠏⠧⠏⠁⠉⠧⠏⠁⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁⠉⠧⠏⠧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠧⡄⡤⠏⠧⡄⠀⠀⠀⠀⠀⠀⡤⠏⠧⡄⡤⠏⠧⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⠇⠯⡅⡤⡄⠀⠀⡤⡄⡭⠇⠯⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⡭⡅⡭⠇⠯⡅⡭⡅⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠯⡅⡭⡅⠀⠀⡭⡅⡭⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⡭⠇⠯⡅⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠧⠏⠁</pre></small></small>
 
=={{header|Python}}==
{{trans|Unicon}}
Note that for Python 3, [http://docs.python.org/py3k/library/functools.html#functools.lru_cache functools.lru_cache] could be used instead of the memoize decorator below.
<langsyntaxhighlight lang="python">from functools import wraps
from turtle import *
 
Line 623 ⟶ 1,929:
 
if __name__ == '__main__':
main()</langsyntaxhighlight>
The output image is probably the same.
 
=={{header|REXXQuackery}}==
Programming note: &nbsp; the starting point ('''.''') and the ending point ('''∙''') are also shown to help visually identify the end points.
<br>About half of the REXX program is dedicated to plotting the appropriate character.
<lang rexx>/*REXX program generates a Fibonacci word, then plots the fractal curve.*/
parse arg ord . /*obtain optional arg from the CL*/
if ord=='' then ord=23 /*Not specified? Then use default*/
s=fibWord(ord) /*obtain the ORD fib word. */
x=0; y=0; maxX=0; maxY=0; dx=0; dy=1; @.=' '; xp=0; yp=0; @.0.0=.
 
<syntaxhighlight lang="Quackery"> [ $ "turtleduck.qky" loadfile ] now!
do n=1 for length(s); x=x+dx; y=y+dy /*advance the plot for next point*/
maxX=max(maxX,x); maxY=max(maxY,y) /*set the maximums for displaying*/
c='│'; if dx\==0 then c='─'; if n==1 then c='┌' /*1st plot.*/
@.x.y=c /*assign a plotting character. */
if @(xp-1,yp)\==' ' & @(xp,yp-1)\==' ' then call @ xp,yp,'┐' /*fixup*/
if @(xp-1,yp)\==' ' & @(xp,yp+1)\==' ' then call @ xp,yp,'┘' /* " */
if @(xp+1,yp)\==' ' & @(xp,yp+1)\==' ' then call @ xp,yp,'└' /* " */
if @(xp+1,yp)\==' ' & @(xp,yp-1)\==' ' then call @ xp,yp,'┌' /* " */
xp=x; yp=y; z=substr(s,n,1) /*save old x,y; assign plot char*/
if z==1 then iterate /*if Z is a "one", then skip it.*/
ox=dx; oy=dy; dx=0; dy=0 /*save DX,DY as the old versions.*/
d=-n//2; if d==0 then d=1 /*determine sign for chirality. */
if oy\==0 then dx=-sign(oy)*d /*Going north|south? Go east|west*/
if ox\==0 then dy= sign(ox)*d /* " east|west? " south|north*/
end /*n*/
 
[ [ ' [ 1 ]
call @ x,y,'∙' /*signify the last point plotted.*/
' [ 0 ]
do r=maxY to 0 by -1; _= /*show a row at a time, top 1st.*/
rot dup 1 = iff
do c=0 to maxX; _=_||@.c.r; end /*c*/
2drop done
if _\='' then say strip(_,'T') /*if not blank, then show a line.*/
dup 2 = iff
end /*r*/ /* [↑] only show non-blank rows.*/
[ drop nip ] done
exit /*stick a fork in it, we're done.*/
2 - times
/*─────────────────────────────────@ subroutine─────────────────────────*/
[ dup rot join ] ]
@: parse arg xx,yy,p; if arg(3)=='' then return @.xx.yy; @.xx.yy=p; return
nip witheach
/*─────────────────────────────────FIBWORD subroutine───────────────────*/
[ 3 2 walk
fibWord: procedure; arg x; !.=0; !.1=1 /*obtain the order of fib word. */
0 = if
do k=3 to x; k1=k-1; k2=k-2 /*generate the Kth Fibonacci word*/
[ i^ 1 &
!.k=!.k1 || !.k2 /*construct the next FIB word. */
end 2 /*k*/ 1 /* [↑] generate Fibonacci words.*/-
return !.x 4 turn ] ] ] is fibofractal ( n --> /*return the Xth fib word. */</lang>)
 
'''output''' when using the input of &nbsp; <tt> 14 </tt>
turtle 0 frames
450 1 fly
1 4 turn
300 1 fly
1 2 turn
23 fibofractal
frame</syntaxhighlight>
 
{{out}}
 
Animation (slowed down to 32 seconds). https://youtu.be/Ap3i2S3gpkc
 
Finished image.
[[File:Quackery Fibonacci word fractal.png|thumb|center]]
 
=={{header|R}}==
{{trans|PARI/GP}}
{{Works with|R|3.3.1 and above}}
[[File:FiboFractR23.png|right|thumb|Output FiboFractR23.png]]
[[File:FiboFractR25.png|right|thumb|Output FiboFractR25.png]]
 
<syntaxhighlight lang="r">
## Fibonacci word/fractal 2/20/17 aev
## Create Fibonacci word order n
fibow <- function(n) {
t2="0"; t1="01"; t="";
if(n<2) {n=2}
for (i in 2:n) {t=paste0(t1,t2); t2=t1; t1=t}
return(t)
}
## Plot Fibonacci word/fractal:
## n - word order, w - width, h - height, d - segment size, clr - color.
pfibofractal <- function(n, w, h, d, clr) {
dx=d; x=y=x2=y2=tx=dy=nr=0;
if(n<2) {n=2}
fw=fibow(n); nf=nchar(fw);
pf = paste0("FiboFractR", n, ".png");
ttl=paste0("Fibonacci word/fractal, n=",n);
cat(ttl,"nf=", nf, "pf=", pf,"\n");
plot(NA, xlim=c(0,w), ylim=c(-h,0), xlab="", ylab="", main=ttl)
for (i in 1:nf) {
fwi=substr(fw, i, i);
x2=x+dx; y2=y+dy;
segments(x, y, x2, y2, col=clr); x=x2; y=y2;
if(fwi=="0") {tx=dx; nr=i%%2;
if(nr==0) {dx=-dy;dy=tx} else {dx=dy;dy=-tx}}
}
dev.copy(png, filename=pf, width=w, height=h); # plot to png-file
dev.off(); graphics.off(); # Cleaning
}
 
## Executing:
pfibofractal(23, 1000, 1000, 1, "navy")
pfibofractal(25, 2300, 1000, 1, "red")
</syntaxhighlight>
 
{{Output}}
<pre>
> pfibofractal(23, 1000, 1000, 1, "navy")
Fibonacci word/fractal, n=23 nf= 75025 pf= FiboFractR23.png
│ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐
> pfibofractal(25, 2300, 1000, 1, "red")
└─┘ │ │ └─┘ │ │ └─┘ │
Fibonacci word/fractal, n=25 nf= 196418 pf= FiboFractR25.png
┌┘ └┐ ┌┘ └┐ ┌┘
│ │ │ ┌─┐ │ │
└┐ ┌┘ └─┘ └─┘ └┐
┌─┐ │ │ ┌─┐ ┌─┐ │
│ └─┘ └─┘ │ │ └─┘
└┐ ┌─┐ ┌─┐ ┌┘ └┐
│ │ └─┘ │ │ │
┌┘ └┐ ┌┘ └┐ ┌┘
│ ┌─┐ │ │ ┌─┐ │ │ ┌─┐
└─┘ └─┘ └─┘ └─┘ └─┘ │
┌─┐ ┌─┐ ┌┘
│ └─┘ │ │
└┐ ┌┘ └┐
│ │ ┌─┐ │
┌┘ └─┘ └─┘
│ ┌─┐
└─┘ │
┌┘
└┐
┌─┐ │
│ └─┘
└┐ ┌─┐ ┌─┐
│ │ └─┘ │
┌┘ └┐ ┌┘
│ ┌─┐ │ │
└─┘ └─┘ └┐
┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ │
│ └─┘ │ │ └─┘ │ │ └─┘
└┐ ┌┘ └┐ ┌┘ └┐
│ │ ┌─┐ │ │ │
┌┘ └─┘ └─┘ └┐ ┌┘
│ ┌─┐ ┌─┐ │ │ ┌─┐
└─┘ │ │ └─┘ └─┘ │
┌┘ └┐ ┌─┐ ┌─┐ ┌┘
│ │ │ └─┘ │ │
└┐ ┌┘ └┐ ┌┘ └┐
┌─┐ │ │ ┌─┐ │ │ ┌─┐ │
. └─┘ └─┘ └─┘ └─┘ └─┘
</pre>
The '''output''' of this REXX program for this Rosetta Code task requirements can be seen here ───► [[Fibonacci word/fractal/FIBFRACT.REX]].
<br><br>
 
=={{header|Racket}}==
Line 725 ⟶ 2,027:
we do not ''generate'' the words here.
 
<langsyntaxhighlight lang="racket">#lang racket
(require "Fibonacci-word.rkt")
(require graphics/value-turtles)
Line 745 ⟶ 2,047:
((_ #\1) (draw 1 T))
(((? even?) #\0) (turn -90 (draw 1 T)))
((_ #\0) (turn 90 (draw 1 T)))))</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>constant @fib-word = '1', '0', { $^b ~ $^a } ... *;
 
sub MAIN($m = 17, $scale = 3) {
(my %world){0}{0} = 1;
my $loc = 0+0i;
my $dir = i;
my $n = 1;
 
for @fib-word[$m].comb {
when '0' {
step;
if $n %% 2 { turn-left }
else { turn-right; }
}
$n++;
}
 
braille-graphics %world;
 
sub step {
for ^$scale {
$loc += $dir;
%world{$loc.im}{$loc.re} = 1;
}
}
 
sub turn-left { $dir *= i; }
sub turn-right { $dir *= -i; }
 
}
 
sub braille-graphics (%a) {
my ($ylo, $yhi, $xlo, $xhi);
for %a.keys -> $y {
$ylo min= +$y; $yhi max= +$y;
for %a{$y}.keys -> $x {
$xlo min= +$x; $xhi max= +$x;
}
}
 
for $ylo, $ylo + 4 ...^ * > $yhi -> \y {
for $xlo, $xlo + 2 ...^ * > $xhi -> \x {
my $cell = 0x2800;
$cell += 1 if %a{y + 0}{x + 0};
$cell += 2 if %a{y + 1}{x + 0};
$cell += 4 if %a{y + 2}{x + 0};
$cell += 8 if %a{y + 0}{x + 1};
$cell += 16 if %a{y + 1}{x + 1};
$cell += 32 if %a{y + 2}{x + 1};
$cell += 64 if %a{y + 3}{x + 0};
$cell += 128 if %a{y + 3}{x + 1};
print chr($cell);
}
print "\n";
}
}</syntaxhighlight>
{{out}}
<small><small><pre>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⡖⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⡁⠀⠀⠀⢈⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠸⠤⡄⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢰⠒⡆⢰⠒⠃⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⣏⣉⠀⣉⣉⠀⠀⠀⠀⣉⣉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣉⣉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣸⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠧⢤⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⢤⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⠃⠀⠀⠀⠘⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣸⠉⣇⣀⠀⣀⣸⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⢤⠀⡤⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⡖⢲⠀⠀⠀⠀⡖⢲⠀⡖⠚⠀⠓⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⡖⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⡁⠀⠀⠀⢈⣉⡁⢈⣉⡇⢸⣉⡁⢈⣉⡁⠀⠀⠀⢈⣉⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⡁⠀⠀⠀⢈⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠧⢤⠀⡤⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢹⣀⡏⠉⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⡄⠀⠀⠀⢠⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⢲⠀⡖⠚⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⣀⣀⠀⠀⠀⠀⣀⣀⠀⣉⣹⠀⣏⣉⠀⣉⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⣀⣀⠀⠀⠀⠀⣀⣀⠀⣉⣹⠀⣏⣉⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⠇⠀⠀⠀⠸⠤⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⡆⢰⠒⠃⠘⠒⡆⢰⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⡆⢰⠒⠃⠘⠒⡆⢰⠒⡆⠀⠀⠀⢰⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣉⠀⠀⠀⠀⣉⣉⠀⣉⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣉⠀⠀⠀⠀⣉⣉⠀⣉⣹⠀⣏⣉⠀⣉⣉⠀⠀⠀⠀⣀⣀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⢈⣉⡇⢸⣉⡁⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⢈⣉⡇⢸⣉⡁⢀⣀⡀⠀⠀⠀⢀⣀⡀⢈⣉⡇⢸⣉⡁⢈⣉⡇⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⢲⠀⠀⠀⠀⡖⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⢲⠀⠀⠀⠀⡖⢲⠀⡖⠚⠀⠓⢲⠀⡖⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⠀⠀⢈⣉⡁⢈⣉⡇⢸⣉⡁⢈⣉⡁⠀⠀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⠀⠀⢈⣉⡁⢈⣉⡇⢸⣉⡁⢈⣉⡁⠀⠀⠀⢈⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠧⢤⠀⡤⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢹⣀⡏⠉⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⡄⠀⠀⠀⢠⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⢲⠀⡖⠚⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⣀⣀⠀⠀⠀⠀⣀⣀⠀⣉⣹⠀⣏⣉⠀⣉⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⢠⠤⠇⠸⠤⠇⠀⠀⠀⠸⠤⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⡆⠀⠀⠀⢰⠒⡆⢰⠒⠃⠘⠒⡆⢰⠒⡆⠀⠀⠀⢰⠒⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⡆⠀⠀⠀⢰⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⠉⠉⠀⠀⠀⠀⠉⠉⠀⣉⣹⠀⣏⣉⠀⣉⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠧⢤⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⢤⠀⡤⠼⠀⠧⢤⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⠃⠀⠀⠀⠘⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⠃⠀⠀⠀⠘⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣸⠉⣇⣸⠉⠁⠈⠉⣇⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠧⢤⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⢤⠀⡤⢤⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢰⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠘⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⠃⠘⠒⡆⢰⠒⠃⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢀⣀⡀⢈⣉⡇⢸⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡤⠼⠀⠧⠼⠀⠀⠀⠀⠧⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠓⢲⠀⡖⢲⠀⠀⠀⠀⡖⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠈⠉⠁⢈⣉⡇⢸⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣉⡁⢈⣉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠸⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠤⠇⠀⠀⠀⠸⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⡆⠀⠀⠀⢰⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣏⣉⠀⣉⣹⠀⣏⣉⠀⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⠃⠀⠀⠀⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠃</pre></small></small>
 
=={{header|REXX}}==
Programming note: &nbsp; the starting point &nbsp; (<big>'''.'''</big>) &nbsp; and the ending point &nbsp; (<big>'''∙'''</big>) &nbsp; are also shown to help visually identify the end points.
 
About half of the REXX program is dedicated to plotting the appropriate characters.
 
If the order of the graph is negative, &nbsp; the graph isn't displayed to the terminal screen.
 
The output of this REXX program is always written to a disk file &nbsp; (named &nbsp; FIBFRACT.OUT).
<syntaxhighlight lang="rexx">/*REXX program generates a Fibonacci word, then (normally) displays the fractal curve.*/
parse arg order . /*obtain optional arguments from the CL*/
if order=='' | order=="," then order= 23 /*Not specified? Then use the default*/
tell= order>=0 /*Negative order? Then don't display. */
s= FibWord( abs(order) ) /*obtain the order of Fibonacci word.*/
x= 0; maxX= 0; dx= 0; b= ' '; @. = b; xp= 0
y= 0; maxY= 0; dy= 1; @.0.0= .; yp= 0
do n=1 for length(s); x= x + dx; y= y + dy /*advance the plot for the next point. */
maxX= max(maxX, x); maxY= max(maxY, y) /*set the maximums for displaying plot.*/
c= '│' /*glyph (character) used for the plot. */
if dx\==0 then c= "─" /*if x+dx isn't zero, use this char.*/
if n==1 then c= '┌' /*is this the first part to be graphed?*/
@.x.y= c /*assign a 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.*/
z= substr(s, n, 1) /*assign a plot character for the graph*/
if z==1 then iterate /*Is Z equal to unity? Then ignore it.*/
ox= dx; oy= dy /*save DX,DY as the old versions. */
dx= 0; dy= 0 /*define DX,DY " " new " */
d= -n//2; if d==0 then d= 1 /*determine the sign for the chirality.*/
if oy\==0 then dx= -sign(oy) * d /*Going north│south? Go east|west */
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 for maxX+1; _= _ || @.c.r /*add a plot character (glyph) to line.*/
end /*c*/ /* [↑] construct a line char by char. */
_= strip(_, 'T') /*construct a line of the graph. */
if _=='' then iterate /*Is the line blank? Then ignore it. */
if tell then say _ /*Display the line to the terminal ? */
call lineout "FIBFRACT.OUT", _ /*write graph to disk (FIBFRACT.OUT). */
end /*r*/ /* [↑] only display the non-blank rows*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: parse arg xx,yy,p; if arg(3)=='' then return @.xx.yy; @.xx.yy= p; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
FibWord: procedure; parse arg x; !.= 0; !.1= 1 /*obtain the order of Fibonacci word. */
do k=3 to x /*generate the Kth " " */
k1= k-1; k2= k - 2 /*calculate the K-1 & K-2 shortcut.*/
!.k= !.k1 || !.k2 /*construct the next Fibonacci word. */
end /*k*/ /* [↑] generate a " " */
return !.x /*return the Xth " " */</syntaxhighlight>
{{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>
<pre style="font-size:13%">
┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐
│ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘
│ │ ┌─┐ │ │ │ │ ┌─┐ │ │ │ │ ┌─┐ │ │ │ │ ┌─┐ │ │
┌┘ └─┘ └─┘ └┐ ┌┘ └─┘ └─┘ └┐ ┌┘ └─┘ └─┘ └┐ ┌┘ └─┘ └─┘ └┐
│ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │
└─┘ │ │ └─┘ └─┘ │ │ └─┘ └─┘ │ │ └─┘ └─┘ │ │ └─┘
┌┘ └┐ ┌─┐ ┌─┐ ┌┘ └┐ ┌┘ └┐ ┌─┐ ┌─┐ ┌┘ └┐
│ │ │ └─┘ │ │ │ │ │ │ └─┘ │ │ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘
┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐
│ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ │ │ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ │
└┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌┘ └┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌┘
│ │ └─┘ │ │ └─┘ │ │ │ │ └─┘ │ │ └─┘ │ │
┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐
│ ┌─┐ │ │ │ │ ┌─┐ │ │ ┌─┐ │ │ │ │ ┌─┐ │
└─┘ └─┘ └┐ ┌┘ └─┘ └─┘ └─┘ └─┘ └┐ ┌┘ └─┘ └─┘
┌─┐ │ │ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ │ │ ┌─┐
│ └─┘ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ └─┘ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘
│ │ │ │ ┌─┐ │ │ │ │
┌┘ └┐ ┌┘ └─┘ └─┘ └┐ ┌┘ └┐
│ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │
└─┘ │ │ └─┘ └─┘ │ │ └─┘ └─┘ │ │ └─┘
┌─┐ ┌─┐ ┌┘ └┐ ┌─┐ ┌─┐ ┌┘ └┐ ┌─┐ ┌─┐ ┌┘ └┐ ┌─┐ ┌─┐
│ └─┘ │ │ │ │ └─┘ │ │ │ │ └─┘ │ │ │ │ └─┘ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘
│ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │
┌┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └┐
│ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ │
└─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘ │ │ └─┘
┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐
│ │ │ ┌─┐ │ │ │ │ ┌─┐ │ │ │
└┐ ┌┘ └─┘ └─┘ └┐ ┌┘ └─┘ └─┘ └┐ ┌┘
┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐
│ └─┘ └─┘ │ │ └─┘ └─┘ │ │ └─┘ └─┘ │
└┐ ┌─┐ ┌─┐ ┌┘ └┐ ┌┘ └┐ ┌─┐ ┌─┐ ┌┘
│ │ └─┘ │ │ │ │ │ │ └─┘ │ │
┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐
│ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │
└─┘ └─┘ └─┘ └─┘ └─┘ │ │ └─┘ └─┘ └─┘ └─┘ └─┘
┌─┐ ┌─┐ ┌┘ └┐ ┌─┐ ┌─┐
│ └─┘ │ │ │ │ └─┘ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘
│ │ ┌─┐ │ │ ┌─┐ │ │
┌┘ └─┘ └─┘ └─┘ └─┘ └┐
│ ┌─┐ ┌─┐ │
└─┘ │ │ └─┘
┌┘ └┐
│ │
└┐ ┌┘
┌─┐ │ │ ┌─┐
│ └─┘ └─┘ │
└┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌┘
│ │ └─┘ │ │ └─┘ │ │
┌┘ └┐ ┌┘ └┐ ┌┘ └┐
│ ┌─┐ │ │ │ │ ┌─┐ │
└─┘ └─┘ └┐ ┌┘ └─┘ └─┘
┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐
│ └─┘ │ │ └─┘ │ │ └─┘ └─┘ │ │ └─┘ │ │ └─┘ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘
│ │ ┌─┐ │ │ │ │ │ │ ┌─┐ │ │
┌┘ └─┘ └─┘ └┐ ┌┘ └┐ ┌┘ └─┘ └─┘ └┐
│ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │ │ ┌─┐ ┌─┐ │
└─┘ │ │ └─┘ └─┘ │ │ └─┘ └─┘ │ │ └─┘
┌┘ └┐ ┌─┐ ┌─┐ ┌┘ └┐ ┌─┐ ┌─┐ ┌┘ └┐
│ │ │ └─┘ │ │ │ │ └─┘ │ │ │
└┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘ └┐ ┌┘
┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐ │ │ ┌─┐
. └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └∙
</pre>
</b>
The '''output''' of this REXX program for this Rosetta Code task requirements can be seen here &nbsp; ───► &nbsp; [[Fibonacci word/fractal/FIBFRACT.REX]].
<br><br>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">def fibonacci_word(n)
words = ["1", "0"]
(n-1).times{ words << words[-1] + words[-2] }
words[n]
end
 
def print_fractal(word)
area = Hash.new(" ")
x = y = 0
dx, dy = 0, -1
area[[x,y]] = "S"
word.each_char.with_index(1) do |c,n|
area[[x+dx, y+dy]] = dx.zero? ? "|" : "-"
x, y = x+2*dx, y+2*dy
area[[x, y]] = "+"
dx,dy = n.even? ? [dy,-dx] : [-dy,dx] if c=="0"
end
(xmin, xmax), (ymin, ymax) = area.keys.transpose.map(&:minmax)
for y in ymin..ymax
puts (xmin..xmax).map{|x| area[[x,y]]}.join
end
end
 
word = fibonacci_word(16)
print_fractal(word)</syntaxhighlight>
 
{{out}}
<pre style="height: 190ex; font-size: 50%;">
+-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+ +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ +
| | | | | | | | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | | | | | | | |
+ + +-+-+ + + + + +-+-+ + + + + +-+-+ + + + + +-+-+ + +
| | | | | | | | | | | | | | | | | | | | | | | |
+-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+
| | | | | | | |
+ +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ +
| | | | | | | | | | | | | | | | | | | | | | | |
+-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+
| | | | | | | |
+-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+
| | | | | | | | | | | | | | | |
+ + + +-+-+ + + + + + + +-+-+ + + +
| | | | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | | | |
+-+-+ + + +-+-+ + + +-+-+ + + +-+-+ +-+-+ + + +-+-+ + + +-+-+ + + +-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ + + +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +
| | | |
+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+
| | | | | | | | | | | | | | | | | | | |
+ + +-+-+ + + +-+-+ + + + + +-+-+ + + +-+-+ + +
| | | | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | | | |
+ +-+-+ + + + + +-+-+ + + +-+-+ + + + + +-+-+ +
| | | | | | | | | | | | | | | | | | | |
+-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+
| | | |
+-+-+ + + +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ + + +-+-+
| | | | | | | | | | | | | | | | | | | |
+ +-+-+ +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ +-+-+ +
| | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | |
+ + + + +-+-+ + + + +
| | | | | | | | | |
+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+
| | | | | |
+ +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ +
| | | | | | | | | | | | | | | | | |
+-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+
| | | | | |
+-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+
| | | | | | | | | | | | | | | | | | | | | |
+ +-+-+ + + + + +-+-+ + + + + +-+-+ + + + + +-+-+ +
| | | | | | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | | | | | |
+ + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + +
| | | | | | | | | | | | | | | | | | | | | | | | | |
+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+
| |
+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +
| | | | | | | | | | | | | | | | | | | | | |
+-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+
| | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | |
+ + + +-+-+ + + + + +-+-+ + + +
| | | | | | | | | | | | | |
+-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+
| | | | | |
+-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+
| | | | | | | | | | | | | | | | | |
+ +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ +
| | | | | |
+-+ +-+-+ +-+-+ +-+ +-+ +-+ +-+ +-+-+ +-+-+ +-+
| | | | | | | | | | | | | |
+ + +-+-+ + + + + + + +-+-+ + +
| | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | |
+ +-+-+ + + +-+-+ + + +-+-+ +-+-+ + + +-+-+ + + +-+-+ +
| | | | | | | | | | | | | | | | | | | | | |
+-+-+ +-+-+ +-+-+ +-+-+ +-+-+ + + +-+-+ +-+-+ +-+-+ +-+-+ +-+-+
| |
+-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+
| | | | | | | | | |
+ +-+-+ + + + + +-+-+ +
| | | | | |
+-+ +-+ +-+ +-+ +-+ +-+
| | | | | |
+ + +-+-+ + + +-+-+ + +
| | | | | | | | | |
+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+
| |
+ +-+-+ +-+-+ +
| | | | | |
+-+-+ + + +-+-+
| |
+-+ +-+
| |
+ +
| |
+-+ +-+
| |
+-+-+ + + +-+-+
| | | | | |
+ +-+-+ +-+-+ +
| |
+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+
| | | | | | | | | |
+ + +-+-+ + + +-+-+ + +
| | | | | |
+-+ +-+ +-+ +-+ +-+ +-+
| | | | | |
+ +-+-+ + + + + +-+-+ +
| | | | | | | | | |
+-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+
| |
+-+-+ +-+-+ +-+-+ +-+-+ +-+-+ + + +-+-+ +-+-+ +-+-+ +-+-+ +-+-+
| | | | | | | | | | | | | | | | | | | | | |
+ +-+-+ + + +-+-+ + + +-+-+ +-+-+ + + +-+-+ + + +-+-+ +
| | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | |
+ + +-+-+ + + + + + + +-+-+ + +
| | | | | | | | | | | | | |
+-+ +-+-+ +-+-+ +-+ +-+ +-+ +-+ +-+-+ +-+-+ +-+
| | | | | |
+ +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ +
| | | | | | | | | | | | | | | | | |
+-+-+ + + +-+-+ +-+-+ + + +-+-+ +-+-+ + + +-+-+
| | | | | |
+-+ +-+ +-+-+ +-+-+ +-+ +-+ +-+-+ +-+-+ +-+ +-+
| | | | | | | | | | | | | |
+ + + +-+-+ + + + + +-+-+ + + +
| | | | | | | | | |
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
| | | | | | | | | |
+-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+ + + +-+-+
| | | | | | | | | | | | | | | | | | | | | |
S +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+-+ +-+
</pre>
 
=={{header|Rust}}==
The output of this program is a file in SVG format.
<syntaxhighlight lang="rust">// [dependencies]
// svg = "0.8.0"
 
use svg::node::element::path::Data;
use svg::node::element::Path;
 
fn fibonacci_word(n: usize) -> Vec<u8> {
let mut f0 = vec![1];
let mut f1 = vec![0];
if n == 0 {
return f0;
} else if n == 1 {
return f1;
}
let mut i = 2;
loop {
let mut f = Vec::with_capacity(f1.len() + f0.len());
f.extend(&f1);
f.extend(f0);
if i == n {
return f;
}
f0 = f1;
f1 = f;
i += 1;
}
}
 
struct FibwordFractal {
current_x: f64,
current_y: f64,
current_angle: i32,
line_length: f64,
max_x: f64,
max_y: f64,
}
 
impl FibwordFractal {
fn new(x: f64, y: f64, length: f64, angle: i32) -> FibwordFractal {
FibwordFractal {
current_x: x,
current_y: y,
current_angle: angle,
line_length: length,
max_x: 0.0,
max_y: 0.0,
}
}
fn execute(&mut self, n: usize) -> Path {
let mut data = Data::new().move_to((self.current_x, self.current_y));
for (i, byte) in fibonacci_word(n).iter().enumerate() {
data = self.draw_line(data);
if *byte == 0u8 {
self.turn(if i % 2 == 1 { -90 } else { 90 });
}
}
Path::new()
.set("fill", "none")
.set("stroke", "black")
.set("stroke-width", "1")
.set("d", data)
}
fn draw_line(&mut self, data: Data) -> Data {
let theta = (self.current_angle as f64).to_radians();
self.current_x += self.line_length * theta.cos();
self.current_y += self.line_length * theta.sin();
if self.current_x > self.max_x {
self.max_x = self.current_x;
}
if self.current_y > self.max_y {
self.max_y = self.current_y;
}
data.line_to((self.current_x, self.current_y))
}
fn turn(&mut self, angle: i32) {
self.current_angle = (self.current_angle + angle) % 360;
}
fn save(file: &str, order: usize) -> std::io::Result<()> {
use svg::node::element::Rectangle;
let x = 5.0;
let y = 5.0;
let rect = Rectangle::new()
.set("width", "100%")
.set("height", "100%")
.set("fill", "white");
let mut ff = FibwordFractal::new(x, y, 1.0, 0);
let path = ff.execute(order);
let document = svg::Document::new()
.set("width", 5 + ff.max_x as usize)
.set("height", 5 + ff.max_y as usize)
.add(rect)
.add(path);
svg::save(file, &document)
}
}
 
fn main() {
FibwordFractal::save("fibword_fractal.svg", 22).unwrap();
}</syntaxhighlight>
 
{{out}}
[[Media:Fibword_fractal_rust.svg]]
 
=={{header|Scala}}==
'''Note:''' will be computing an SVG image - not very efficient, but very cool. worked for me in the scala REPL with ''-J-Xmx2g'' argument.
<syntaxhighlight lang="scala">
def fibIt = Iterator.iterate(("1","0")){case (f1,f2) => (f2,f1+f2)}.map(_._1)
 
def turnLeft(c: Char): Char = c match {
case 'R' => 'U'
case 'U' => 'L'
case 'L' => 'D'
case 'D' => 'R'
}
 
def turnRight(c: Char): Char = c match {
case 'R' => 'D'
case 'D' => 'L'
case 'L' => 'U'
case 'U' => 'R'
}
 
def directions(xss: List[(Char,Char)], current: Char = 'R'): List[Char] = xss match {
case Nil => current :: Nil
case x :: xs => x._1 match {
case '1' => current :: directions(xs, current)
case '0' => x._2 match {
case 'E' => current :: directions(xs, turnLeft(current))
case 'O' => current :: directions(xs, turnRight(current))
}
}
}
def buildIt(xss: List[Char], old: Char = 'X', count: Int = 1): List[String] = xss match {
case Nil => s"$old$count" :: Nil
case x :: xs if x == old => buildIt(xs,old,count+1)
case x :: xs => s"$old$count" :: buildIt(xs,x)
}
def convertToLine(s: String, c: Int): String = (s.head, s.tail) match {
case ('R',n) => s"l ${c * n.toInt} 0"
case ('U',n) => s"l 0 ${-c * n.toInt}"
case ('L',n) => s"l ${-c * n.toInt} 0"
case ('D',n) => s"l 0 ${c * n.toInt}"
}
 
def drawSVG(xStart: Int, yStart: Int, width: Int, height: Int, fibWord: String, lineMultiplier: Int, color: String): String = {
val xs = fibWord.zipWithIndex.map{case (c,i) => (c, if(c == '1') '_' else i % 2 match{case 0 => 'E'; case 1 => 'O'})}.toList
val fractalPath = buildIt(directions(xs)).tail.map(convertToLine(_,lineMultiplier))
s"""<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="${width}px" height="${height}px" viewBox="0 0 $width $height"><path d="M $xStart $yStart ${fractalPath.mkString(" ")}" style="stroke:#$color;stroke-width:1" stroke-linejoin="miter" fill="none"/></svg>"""
}
 
drawSVG(0,25,550,530,fibIt.drop(18).next,3,"000")
</syntaxhighlight>
 
{{out}}
 
[https://www.dropbox.com/s/vb4cu4fvq2f6cvz/fibfract.svg?dl=0 output string saved as an SVG file] - BTW, would appreciate help on getting the image to display here nicely. couldn't figure out how to do that...
 
=={{header|Scilab}}==
This script uses Scilab's [[Fibonacci_word#Iterative_method|iterative solution]] to generate Fibonacci words, and the interpreting the words to generate the fractal is similar to [[Langton's_ant#Scilab|Langton's ant]]. The result is displayed in a graphic window.
 
<syntaxhighlight lang="text">final_length = 37;
 
word_n = '';
word_n_1 = '';
word_n_2 = '';
 
for i = 1:final_length
if i == 1 then
word_n = '1';
elseif i == 2
word_n = '0';
elseif i == 3
word_n = '01';
word_n_1 = '0';
else
word_n_2 = word_n_1;
word_n_1 = word_n;
word_n = word_n_1 + word_n_2;
end
end
 
word = strsplit(word_n);
fractal_size = sum(word' == '0');
fractal = zeros(1+fractal_size,2);
 
direction_vectors = [1,0; 0,-1; -1,0; 0,1];
direction = direction_vectors(4,:);
direction_name = 'N';
 
for j = 1:length(word_n);
fractal(j+1,:) = fractal(j,:) + direction;
if word(j) == '0' then
if pmodulo(j,2) then
//right
select direction_name
case 'N' then
direction = direction_vectors(1,:);
direction_name = 'E';
case 'E' then
direction = direction_vectors(2,:);
direction_name = 'S';
case 'S' then
direction = direction_vectors(3,:);
direction_name = 'W';
case 'W' then
direction = direction_vectors(4,:);
direction_name = 'N';
end
else
//left
select direction_name
case 'N' then
direction = direction_vectors(3,:);
direction_name = 'W';
case 'W' then
direction = direction_vectors(2,:);
direction_name = 'S';
case 'S' then
direction = direction_vectors(1,:);
direction_name = 'E';
case 'E' then
direction = direction_vectors(4,:);
direction_name = 'N';
end
end
end
end
 
scf(0); clf();
plot2d(fractal(:,1),fractal(:,2));
set(gca(),'isoview','on');</syntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
<syntaxhighlight lang="ruby">var(m=17, scale=3) = ARGV.map{.to_i}...
 
(var world = Hash.new){0}{0} = 1
var loc = 0
var dir = 1i
 
var fib = ['1', '0']
func fib_word(n) {
fib[n] \\= (fib_word(n-1) + fib_word(n-2))
}
 
func step {
scale.times {
loc += dir
world{loc.im}{loc.re} = 1
}
}
 
func turn_left { dir *= 1i }
func turn_right { dir *= -1i }
 
var n = 1
fib_word(m).each { |c|
if (c == '0') {
step()
n % 2 == 0 ? turn_left()
: turn_right()
} else { n++ }
}
 
func braille_graphics(a) {
var (xlo, xhi, ylo, yhi) = ([Inf, -Inf]*2)...
 
a.each_key { |y|
ylo.min!(y.to_i)
yhi.max!(y.to_i)
a{y}.each_key { |x|
xlo.min!(x.to_i)
xhi.max!(x.to_i)
}
}
 
for y in (ylo..yhi `by` 4) {
for x in (xlo..xhi `by` 2) {
var cell = 0x2800
 
a{y+0}{x+0} && (cell += 1)
a{y+1}{x+0} && (cell += 2)
a{y+2}{x+0} && (cell += 4)
a{y+0}{x+1} && (cell += 8)
a{y+1}{x+1} && (cell += 16)
a{y+2}{x+1} && (cell += 32)
a{y+3}{x+0} && (cell += 64)
a{y+3}{x+1} && (cell += 128)
 
print cell.chr
}
print "\n"
}
}
 
braille_graphics(world)</syntaxhighlight>
{{out}}
<pre>
$ sidef fib_word_fractal.sf 12 3
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⢤⠀⡤⠼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠒⠃⠘⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣇⣸⠉⣇⣀⠀⣀⣸⠉⣇⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⡖⢲⠀⠀
⠀⠀⠀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⡁⠀⠀⠀⢈⣉⡁⢈⣉⡇
⠀⠀⠀⡤⠼⠀⠧⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠼⠀⠧⢤⠀⡤⠼⠀⠧⠼⠀⠀
⠀⠀⠀⠓⢲⠀⡖⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢲⠀⡖⠚⠀⠓⢲⠀⠀⠀⠀⠀
⠉⢹⣀⡏⠉⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠉⢹⣀⡏⠉⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢠⠤⡄⢠⠤⠇⠸⠤⡄⢠⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡖⠚⠀⠓⠚⠀⠀⠀⠀⠓⠚⠀⠓⢲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠉⢹⣀⡏⢹⣀⡀⢀⣀⡏⢹⣀⡏⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠤⠇⠸⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠒⡆⢰⠒⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
</pre>
 
=={{header|Tcl}}==
{{libheader|Tk}}
<!-- I've tested this up to F_37; it required a *lot* of memory (good thing I'm using a 64-bit build…) -->
<langsyntaxhighlight lang="tcl">package require Tk
 
# OK, this stripped down version doesn't work for n<2…
Line 793 ⟶ 2,856:
 
pack [canvas .c -width 500 -height 500]
drawFW .c [fibword 23]</langsyntaxhighlight>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "dome" for Window
 
class FibonacciWordFractal {
construct new(width, height, n) {
Window.title = "Fibonacci Word Fractal"
Window.resize(width, height)
Canvas.resize(width, height)
_fore = Color.green
_wordFractal = wordFractal(n)
}
 
init() {
drawWordFractal(20, 20, 1, 0)
}
 
wordFractal(i) {
if (i < 2) return (i == 1) ? "1" : ""
var f1 = "1"
var f2 = "0"
for (j in i-2...0) {
var tmp = f2
f2 = f2 + f1
f1 = tmp
}
return f2
}
 
drawWordFractal(x, y, dx, dy) {
for (i in 0..._wordFractal.count) {
Canvas.line(x, y, x + dx, y + dy, _fore)
x = x + dx
y = y + dy
if (_wordFractal[i] == "0") {
var tx = dx
dx = (i % 2 == 0) ? -dy : dy
dy = (i % 2 == 0) ? tx : - tx
}
}
}
 
update() {}
 
draw(alpha) {}
}
 
var Game = FibonacciWordFractal.new(450, 620, 23)</syntaxhighlight>
 
=={{header|zkl}}==
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
{{trans|D}}
[[File:Fibonacci word fractal.zkl.jpg|250px|thumb|right]]
<syntaxhighlight lang="zkl">fcn drawFibonacci(img,x,y,word){ // word is "01001010...", 75025 characters
dx:=0; dy:=1; // turtle direction
foreach i,c in ([1..].zip(word)){ // Walker.zip(list)-->Walker of zipped list
a:=x; b:=y; x+=dx; y+=dy;
img.line(a,b, x,y, 0x00ff00);
if (c=="0"){
dxy:=dx+dy;
if(i.isEven){ dx=(dx - dxy)%2; dy=(dxy - dy)%2; }// turn left
else { dx=(dxy - dx)%2; dy=(dy - dxy)%2; }// turn right
}
}
}
 
img:=PPM(1050,1050);
fibWord:=L("1","0"); do(23){ fibWord.append(fibWord[-1] + fibWord[-2]); }
drawFibonacci(img,20,20,fibWord[-1]);
img.write(File("foo.ppm","wb"));</syntaxhighlight>
2,120

edits