Jump to content

Fibonacci word/fractal: Difference between revisions

+ D entry
(→‎Tcl: Added implementation)
(+ D entry)
Line 10:
 
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].
 
=={{header|D}}==
This uses the turtle module from the Dragon Curve Task, and the module from the Grayscale Image task.
{{trans|Python}}
<lang d>import std.range, grayscale_image, turtle;
 
void drawFibonacci(Color)(Image!Color img, ref Turtle t,
in string word, in real step) {
foreach (immutable i, immutable c; word) {
t.forward(img, step);
if (c == '0') {
if ((i + 1) % 2 == 0)
t.left(90);
else
t.right(90);
}
}
}
 
void main() {
auto img = new Image!Gray(1050, 1050);
auto t = Turtle(30, 1010, -90);
const w = recurrence!q{a[n-1] ~ a[n-2]}("1", "0").drop(24).front;
img.drawFibonacci(t, w, 1);
img.savePGM("fibonacci_word_fractal.pgm");
}</lang>
It prints the level 25 word as the Python entry.
 
=={{header|Icon}} and {{header|Unicon}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.