Fibonacci word/fractal: Difference between revisions
Content added Content deleted
m (J: clearer description) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 24: | Line 24: | ||
Prints F_Word<sub>30</sub> currently. Segment length and F_Word<sub>n</sub> can be adjusted. |
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]. |
{{libheader|GDIP}}Also see the [http://www.autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/ Gdip examples]. |
||
< |
<syntaxhighlight lang="autohotkey">#NoEnv |
||
SetBatchLines, -1 |
SetBatchLines, -1 |
||
p := 0.3 ; Segment length (pixels) |
p := 0.3 ; Segment length (pixels) |
||
Line 98: | Line 98: | ||
Gdip_DeleteGraphics(G) |
Gdip_DeleteGraphics(G) |
||
Gdip_Shutdown(pToken) |
Gdip_Shutdown(pToken) |
||
ExitApp</ |
ExitApp</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
Writes an EPS file that has the 26th fractal. This is probably cheating. |
Writes an EPS file that has the 26th fractal. This is probably cheating. |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
int main(void) |
int main(void) |
||
Line 118: | Line 118: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp"> |
||
#include <windows.h> |
#include <windows.h> |
||
#include <string> |
#include <string> |
||
Line 291: | Line 291: | ||
return system( "pause" ); |
return system( "pause" ); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
This uses the turtle module from the Dragon Curve Task, and the module from the Grayscale Image task. |
This uses the turtle module from the Dragon Curve Task, and the module from the Grayscale Image task. |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="d">import std.range, grayscale_image, turtle; |
||
void drawFibonacci(Color)(Image!Color img, ref Turtle t, |
void drawFibonacci(Color)(Image!Color img, ref Turtle t, |
||
Line 317: | Line 317: | ||
img.drawFibonacci(t, w, 1); |
img.drawFibonacci(t, w, 1); |
||
img.savePGM("fibonacci_word_fractal.pgm"); |
img.savePGM("fibonacci_word_fractal.pgm"); |
||
}</ |
}</syntaxhighlight> |
||
It prints the level 25 word as the Python entry. |
It prints the level 25 word as the Python entry. |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
{{libheader| System.SysUtils}} |
{{libheader| System.SysUtils}} |
||
{{libheader| Vcl.Graphics}} |
{{libheader| Vcl.Graphics}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program Fibonacci_word; |
program Fibonacci_word; |
||
Line 410: | Line 410: | ||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
{{trans|Ruby}} |
{{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 fibonacci_word, do: Stream.unfold({"1","0"}, fn{a,b} -> {a, {b, b<>a}} end) |
||
Line 445: | Line 445: | ||
end |
end |
||
Fibonacci.word_fractal(16)</ |
Fibonacci.word_fractal(16)</syntaxhighlight> |
||
Output is same as Ruby. |
Output is same as Ruby. |
||
Line 452: | Line 452: | ||
<p>Points to note:</p> |
<p>Points to note:</p> |
||
<ul> |
<ul> |
||
<li>Rather than using the "usual" Fibonacci catamorphismen < |
<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 σ: 0 → 01, 1 → 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 ∩ formed or ⊃ 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> |
<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 ∩ formed or ⊃ 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> |
</ul> |
||
< |
<syntaxhighlight lang="fsharp">let sigma s = seq { |
||
for c in s do if c = '1' then yield '0' else yield '0'; yield '1' |
for c in s do if c = '1' then yield '0' else yield '0'; yield '1' |
||
} |
} |
||
Line 500: | Line 500: | ||
Sorry, your browser does not support inline SVG. |
Sorry, your browser does not support inline SVG. |
||
</svg></body></html>""" (viewboxHeight-1) |
</svg></body></html>""" (viewboxHeight-1) |
||
0</ |
0</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<p>Since file upload to the Wiki is not possible, the raw output for F<sub>11</sub> is given:</p> |
<p>Since file upload to the Wiki is not possible, the raw output for F<sub>11</sub> is given:</p> |
||
Line 510: | Line 510: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: accessors arrays combinators fry images images.loader |
||
kernel literals make match math math.vectors pair-rocket |
kernel literals make match math math.vectors pair-rocket |
||
sequences ; |
sequences ; |
||
Line 578: | Line 578: | ||
save-graphic-image ; |
save-graphic-image ; |
||
MAIN: main</ |
MAIN: main</syntaxhighlight> |
||
{{out}} Similar to fig. 1 from the paper and the image at the top of this page. |
{{out}} Similar to fig. 1 from the paper and the image at the top of this page. |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
On a Windows 32bit system F_word35 is the biggest that can be drawn. |
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 |
' compile with: fbc -s console "filename".bas |
||
Line 691: | Line 691: | ||
Sleep |
Sleep |
||
ImageDestroy(img_ptr) ' free memory holding the image |
ImageDestroy(img_ptr) ' free memory holding the image |
||
Loop</ |
Loop</syntaxhighlight> |
||
=={{header|Fōrmulæ}}== |
=={{header|Fōrmulæ}}== |
||
Line 704: | Line 704: | ||
{{libheader|Go Graphics}} |
{{libheader|Go Graphics}} |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 760: | Line 760: | ||
dc.Stroke() |
dc.Stroke() |
||
dc.SavePNG("fib_wordfractal.png") |
dc.SavePNG("fib_wordfractal.png") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 772: | Line 772: | ||
a single pixel. |
a single pixel. |
||
< |
<syntaxhighlight lang="unicon">global width, height |
||
procedure main(A) |
procedure main(A) |
||
Line 828: | Line 828: | ||
DrawLine(p.x,p.y, p1.x,p1.y) |
DrawLine(p.x,p.y, p1.x,p1.y) |
||
return p1 |
return p1 |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Data.List (unfoldr) |
||
import Data.Bool (bool) |
import Data.Bool (bool) |
||
import Data.Semigroup (Sum(..), Min(..), Max(..)) |
import Data.Semigroup (Sum(..), Min(..), Max(..)) |
||
Line 862: | Line 862: | ||
, "</svg>"] |
, "</svg>"] |
||
main = writeFile "test.html" $ toSVG $ fibonacciWord True False !! 21</ |
main = writeFile "test.html" $ toSVG $ fibonacciWord True False !! 21</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
Line 868: | Line 868: | ||
Plotting the fractal as a parametric equation, this looks reasonably nice: |
Plotting the fractal as a parametric equation, this looks reasonably nice: |
||
< |
<syntaxhighlight lang="j">require 'plot' |
||
plot }:+/\ 0,*/\(^~ 0j_1 0j1 $~ #)'0'=_1{::F_Words 20</ |
plot }:+/\ 0,*/\(^~ 0j_1 0j1 $~ #)'0'=_1{::F_Words 20</syntaxhighlight> |
||
Note that we need the definition of F_Words from the [[Fibonacci_word#J|Fibonacci word]] page: |
Note that we need the definition of F_Words from the [[Fibonacci_word#J|Fibonacci word]] page: |
||
< |
<syntaxhighlight lang="j">F_Words=: (,<@;@:{~&_1 _2)@]^:(2-~[)&('1';'0')</syntaxhighlight> |
||
However, image uploads are currently disabled, and rendering images of this sort as wikitext gets bulky. |
However, image uploads are currently disabled, and rendering images of this sort as wikitext gets bulky. |
||
Line 884: | Line 884: | ||
[[File:fib_word_fractal_java.gif|300px|thumb|right]] |
[[File:fib_word_fractal_java.gif|300px|thumb|right]] |
||
{{works with|Java|8}} |
{{works with|Java|8}} |
||
< |
<syntaxhighlight lang="java">import java.awt.*; |
||
import javax.swing.*; |
import javax.swing.*; |
||
Line 950: | Line 950: | ||
}); |
}); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 958: | Line 958: | ||
[[File:FiboWFractal1.png|200px|right|thumb|Output FiboWFractal1.png]] |
[[File:FiboWFractal1.png|200px|right|thumb|Output FiboWFractal1.png]] |
||
< |
<syntaxhighlight lang="javascript"> |
||
// Plot Fibonacci word/fractal |
// Plot Fibonacci word/fractal |
||
// FiboWFractal.js - 6/27/16 aev |
// FiboWFractal.js - 6/27/16 aev |
||
Line 988: | Line 988: | ||
return(fw) |
return(fw) |
||
} |
} |
||
</ |
</syntaxhighlight> |
||
'''Executing:''' |
'''Executing:''' |
||
< |
<syntaxhighlight lang="html"> |
||
<!-- FiboWFractal2.html --> |
<!-- FiboWFractal2.html --> |
||
<html> |
<html> |
||
Line 1,015: | Line 1,015: | ||
</body> |
</body> |
||
</html> |
</html> |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 1,027: | Line 1,027: | ||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
< |
<syntaxhighlight lang="julia">using Luxor, Colors |
||
function fwfractal!(word::AbstractString, t::Turtle) |
function fwfractal!(word::AbstractString, t::Turtle) |
||
Line 1,049: | Line 1,049: | ||
fwfractal!(word, t) |
fwfractal!(word, t) |
||
finish() |
finish() |
||
preview()</ |
preview()</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1.2 |
||
import java.awt.* |
import java.awt.* |
||
Line 1,122: | Line 1,122: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
Line 1,128: | Line 1,128: | ||
{{works with|UCB Logo}} |
{{works with|UCB Logo}} |
||
< |
<syntaxhighlight lang="logo">; Return the low 1-bits of :n |
||
; For example if n = binary 10110111 = 183 |
; For example if n = binary 10110111 = 183 |
||
; then return binary 111 = 7 |
; then return binary 111 = 7 |
||
Line 1,156: | Line 1,156: | ||
setheading 0 ; initial line North |
setheading 0 ; initial line North |
||
fibonacci.word.fractal 377</ |
fibonacci.word.fractal 377</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
===LÖVE=== |
===LÖVE=== |
||
Needs LÖVE 2D Engine |
Needs LÖVE 2D Engine |
||
< |
<syntaxhighlight lang="lua"> |
||
RIGHT, LEFT, UP, DOWN = 1, 2, 4, 8 |
RIGHT, LEFT, UP, DOWN = 1, 2, 4, 8 |
||
function drawFractals( w ) |
function drawFractals( w ) |
||
Line 1,210: | Line 1,210: | ||
love.graphics.draw( canvas ) |
love.graphics.draw( canvas ) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
===ASCII=== |
===ASCII=== |
||
Uses the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending.. |
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 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 |
local word, x, y, dx, dy = fw(n), 0, self.height-1, 0, -1 |
||
Line 1,236: | Line 1,236: | ||
bitmap:clear(" ") |
bitmap:clear(" ") |
||
bitmap:fiboword(14) |
bitmap:fiboword(14) |
||
bitmap:render()</ |
bitmap:render()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="font-size:50%">| |
<pre style="font-size:50%">| |
||
Line 1,323: | Line 1,323: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{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*) |
without exposing it to the global scope*) |
||
Module[{FibonacciWord, step}, |
Module[{FibonacciWord, step}, |
||
Line 1,338: | Line 1,338: | ||
steps = MapIndexed[step, Characters[FibonacciWord[n]]]; |
steps = MapIndexed[step, Characters[FibonacciWord[n]]]; |
||
dirs = ComposeList[steps, {0, 1}]; |
dirs = ComposeList[steps, {0, 1}]; |
||
Graphics[Line[FoldList[Plus, {0, 0}, dirs]]]]];</ |
Graphics[Line[FoldList[Plus, {0, 0}, dirs]]]]];</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{libheader|imageman}} |
{{libheader|imageman}} |
||
< |
<syntaxhighlight lang="nim">import imageman |
||
const |
const |
||
Line 1,386: | Line 1,386: | ||
# Save into a PNG file. |
# Save into a PNG file. |
||
image.savePNG(Output, compression = 9)</ |
image.savePNG(Output, compression = 9)</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Line 1,401: | Line 1,401: | ||
{{Works with|PARI/GP|2.7.4 and above}} |
{{Works with|PARI/GP|2.7.4 and above}} |
||
< |
<syntaxhighlight lang="parigp"> |
||
\\ Fibonacci word/fractals |
\\ Fibonacci word/fractals |
||
\\ 4/25/16 aev |
\\ 4/25/16 aev |
||
Line 1,448: | Line 1,448: | ||
plotfibofract(21,430,2); \\ Fibofrac2.png |
plotfibofract(21,430,2); \\ Fibofrac2.png |
||
} |
} |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 1,471: | Line 1,471: | ||
{{Works with|PARI/GP|2.7.4 and above}} |
{{Works with|PARI/GP|2.7.4 and above}} |
||
< |
<syntaxhighlight lang="parigp"> |
||
\\ Fibonacci word/fractals 2nd version |
\\ Fibonacci word/fractals 2nd version |
||
\\ 4/26/16 aev |
\\ 4/26/16 aev |
||
Line 1,499: | Line 1,499: | ||
plotfibofract1(21,600,1); \\ Fibofrac4.png |
plotfibofract1(21,600,1); \\ Fibofrac4.png |
||
} |
} |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 1,513: | Line 1,513: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Creates file fword.png containing the Fibonacci Fractal. |
Creates file fword.png containing the Fibonacci Fractal. |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use GD; |
use GD; |
||
Line 1,549: | Line 1,549: | ||
print $out $im->png; |
print $out $im->png; |
||
close $out; |
close $out; |
||
</syntaxhighlight> |
|||
</lang> |
|||
===Using Tk=== |
===Using Tk=== |
||
This draws a segment at a time so you can watch it grow :) |
This draws a segment at a time so you can watch it grow :) |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
use strict; # https://rosettacode.org/wiki/Fibonacci_word |
use strict; # https://rosettacode.org/wiki/Fibonacci_word |
||
Line 1,594: | Line 1,594: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,601: | Line 1,601: | ||
You can run this online [http://phix.x10.mx/p2js/fibonaccifractal.htm here]. |
You can run this online [http://phix.x10.mx/p2js/fibonaccifractal.htm here]. |
||
Output matches Fig 1 (at the top of the page) |
Output matches Fig 1 (at the top of the page) |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\FibonacciFractal.exw |
-- demo\rosetta\FibonacciFractal.exw |
||
Line 1,653: | Line 1,653: | ||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
Written in Processing ([http://www.processing.org Processing]) |
Written in Processing ([http://www.processing.org Processing]) |
||
< |
<syntaxhighlight lang="processing"> |
||
int n = 18; |
int n = 18; |
||
String f1 = "1"; |
String f1 = "1"; |
||
Line 1,696: | Line 1,696: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{trans|Unicon}} |
{{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. |
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. |
||
< |
<syntaxhighlight lang="python">from functools import wraps |
||
from turtle import * |
from turtle import * |
||
Line 1,758: | Line 1,758: | ||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
The output image is probably the same. |
The output image is probably the same. |
||
Line 1,767: | Line 1,767: | ||
[[File:FiboFractR25.png|right|thumb|Output FiboFractR25.png]] |
[[File:FiboFractR25.png|right|thumb|Output FiboFractR25.png]] |
||
<syntaxhighlight lang="r"> |
|||
<lang r> |
|||
## Fibonacci word/fractal 2/20/17 aev |
## Fibonacci word/fractal 2/20/17 aev |
||
## Create Fibonacci word order n |
## Create Fibonacci word order n |
||
Line 1,800: | Line 1,800: | ||
pfibofractal(23, 1000, 1000, 1, "navy") |
pfibofractal(23, 1000, 1000, 1, "navy") |
||
pfibofractal(25, 2300, 1000, 1, "red") |
pfibofractal(25, 2300, 1000, 1, "red") |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 1,822: | Line 1,822: | ||
we do not ''generate'' the words here. |
we do not ''generate'' the words here. |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(require "Fibonacci-word.rkt") |
(require "Fibonacci-word.rkt") |
||
(require graphics/value-turtles) |
(require graphics/value-turtles) |
||
Line 1,842: | Line 1,842: | ||
((_ #\1) (draw 1 T)) |
((_ #\1) (draw 1 T)) |
||
(((? even?) #\0) (turn -90 (draw 1 T))) |
(((? even?) #\0) (turn -90 (draw 1 T))) |
||
((_ #\0) (turn 90 (draw 1 T)))))</ |
((_ #\0) (turn 90 (draw 1 T)))))</syntaxhighlight> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>constant @fib-word = '1', '0', { $^b ~ $^a } ... *; |
||
sub MAIN($m = 17, $scale = 3) { |
sub MAIN($m = 17, $scale = 3) { |
||
Line 1,901: | Line 1,901: | ||
print "\n"; |
print "\n"; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<small><small><pre>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ |
<small><small><pre>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ |
||
Line 1,987: | Line 1,987: | ||
The output of this REXX program is always written to a disk file (named FIBFRACT.OUT). |
The output of this REXX program is always written to a disk file (named 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*/ |
parse arg order . /*obtain optional arguments from the CL*/ |
||
if order=='' | order=="," then order= 23 /*Not specified? Then use the default*/ |
if order=='' | order=="," then order= 23 /*Not specified? Then use the default*/ |
||
Line 2,033: | Line 2,033: | ||
!.k= !.k1 || !.k2 /*construct the next Fibonacci word. */ |
!.k= !.k1 || !.k2 /*construct the next Fibonacci word. */ |
||
end /*k*/ /* [↑] generate a " " */ |
end /*k*/ /* [↑] generate a " " */ |
||
return !.x /*return the Xth " " */</ |
return !.x /*return the Xth " " */</syntaxhighlight> |
||
{{out|output|text= when using the input of: <tt> 17 </tt>}} |
{{out|output|text= when using the input of: <tt> 17 </tt>}} |
||
<br><br>(The output is shown <sup>1</sup>/<sub>8</sub> size.) |
<br><br>(The output is shown <sup>1</sup>/<sub>8</sub> size.) |
||
Line 2,114: | Line 2,114: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">def fibonacci_word(n) |
||
words = ["1", "0"] |
words = ["1", "0"] |
||
(n-1).times{ words << words[-1] + words[-2] } |
(n-1).times{ words << words[-1] + words[-2] } |
||
Line 2,139: | Line 2,139: | ||
word = fibonacci_word(16) |
word = fibonacci_word(16) |
||
print_fractal(word)</ |
print_fractal(word)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,286: | Line 2,286: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
The output of this program is a file in SVG format. |
The output of this program is a file in SVG format. |
||
< |
<syntaxhighlight lang="rust">// [dependencies] |
||
// svg = "0.8.0" |
// svg = "0.8.0" |
||
Line 2,384: | Line 2,384: | ||
fn main() { |
fn main() { |
||
FibwordFractal::save("fibword_fractal.svg", 22).unwrap(); |
FibwordFractal::save("fibword_fractal.svg", 22).unwrap(); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,391: | Line 2,391: | ||
=={{header|Scala}}== |
=={{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. |
'''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 fibIt = Iterator.iterate(("1","0")){case (f1,f2) => (f2,f1+f2)}.map(_._1) |
||
Line 2,439: | Line 2,439: | ||
drawSVG(0,25,550,530,fibIt.drop(18).next,3,"000") |
drawSVG(0,25,550,530,fibIt.drop(18).next,3,"000") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 2,448: | Line 2,448: | ||
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. |
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. |
||
<lang>final_length = 37; |
<syntaxhighlight lang="text">final_length = 37; |
||
word_n = ''; |
word_n = ''; |
||
Line 2,518: | Line 2,518: | ||
scf(0); clf(); |
scf(0); clf(); |
||
plot2d(fractal(:,1),fractal(:,2)); |
plot2d(fractal(:,1),fractal(:,2)); |
||
set(gca(),'isoview','on');</ |
set(gca(),'isoview','on');</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="ruby">var(m=17, scale=3) = ARGV.map{.to_i}... |
||
(var world = Hash.new){0}{0} = 1 |
(var world = Hash.new){0}{0} = 1 |
||
Line 2,583: | Line 2,583: | ||
} |
} |
||
braille_graphics(world)</ |
braille_graphics(world)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,608: | Line 2,608: | ||
{{libheader|Tk}} |
{{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…) --> |
<!-- I've tested this up to F_37; it required a *lot* of memory (good thing I'm using a 64-bit build…) --> |
||
< |
<syntaxhighlight lang="tcl">package require Tk |
||
# OK, this stripped down version doesn't work for n<2… |
# OK, this stripped down version doesn't work for n<2… |
||
Line 2,651: | Line 2,651: | ||
pack [canvas .c -width 500 -height 500] |
pack [canvas .c -width 500 -height 500] |
||
drawFW .c [fibword 23]</ |
drawFW .c [fibword 23]</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
< |
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color |
||
import "dome" for Window |
import "dome" for Window |
||
Line 2,702: | Line 2,702: | ||
} |
} |
||
var Game = FibonacciWordFractal.new(450, 620, 23)</ |
var Game = FibonacciWordFractal.new(450, 620, 23)</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Line 2,708: | Line 2,708: | ||
{{trans|D}} |
{{trans|D}} |
||
[[File:Fibonacci word fractal.zkl.jpg|250px|thumb|right]] |
[[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 |
dx:=0; dy:=1; // turtle direction |
||
foreach i,c in ([1..].zip(word)){ // Walker.zip(list)-->Walker of zipped list |
foreach i,c in ([1..].zip(word)){ // Walker.zip(list)-->Walker of zipped list |
||
Line 2,724: | Line 2,724: | ||
fibWord:=L("1","0"); do(23){ fibWord.append(fibWord[-1] + fibWord[-2]); } |
fibWord:=L("1","0"); do(23){ fibWord.append(fibWord[-1] + fibWord[-2]); } |
||
drawFibonacci(img,20,20,fibWord[-1]); |
drawFibonacci(img,20,20,fibWord[-1]); |
||
img.write(File("foo.ppm","wb"));</ |
img.write(File("foo.ppm","wb"));</syntaxhighlight> |