
The Fibonacci word may be represented as a fractal as described here:


(Clicking on the above website   (hal.archives-ouvertes.fr)    will leave a cookie.)



For F_wordm start with F_wordCharn=1
Draw a segment forward
If current F_wordChar is 0
Turn left if n is even
Turn right if n is odd
next n and iterate until end of F_word


Task

Create and display a fractal similar to Fig 1.


(Clicking on the above website   (hal.archives-ouvertes.fr)    will leave a cookie.)

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)