

Task
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.

width = 64
 
sub hilbert(x, y, lg, i1, i2)
    if lg = 1 then
        line to (width-x) * 10, (width-y) * 10
        return
    end if
    lg = lg / 2
    hilbert(x+i1*lg, y+i1*lg, lg, i1, 1-i2)
    hilbert(x+i2*lg, y+(1-i2)*lg, lg, i1, i2)
    hilbert(x+(1-i1)*lg, y+(1-i1)*lg, lg, i1, i2)
    hilbert(x+(1-i2)*lg, y+i2*lg, lg, 1-i1, i2)
end sub
 
open window 655, 655
 
hilbert(0, 0, width, 0, 0)