Hilbert curve: Difference between revisions

Completed ASCII line drawing with turnarounds
(Completed ASCII line drawing with turnarounds)
Line 403:
 
Lindenmayer:
 
* A,B are Lindenmayer AXIOMS
 
Line drawing:
 
* +,- turn right, left
* F draw line forward
* <num> repeat the following draw command <num> times
* <any> move on canvas without drawing
<lang lua>-- any version from LuaJIT 2.0/5.1, Lua 5.2, Lua 5.3 to LuaJIT 2.1.0-beta3-readline
local bit=bit32 or bit -- Lua 5.2/5.3 compatibilty
Line 439 ⟶ 441:
function draw(s)
local char={
{"─","┘","╴","┐",}, -- r
{"│","┐","╷","┌",}, -- up
{"─","┌","╶","└",}, -- l
{"│","└","╵","┘",}, -- down
}
local scr={}
Line 498 ⟶ 500:
draw(str:hilbert(n))
</lang>
{{output}} luajit hilbert.lua 4 10FAF1M9FAF-4F2+2F-2F-2F++4F-F-4F+2F+2F+2F++3F+2F+3F--4FA10F-16F-58F-16F-
<pre>
┌─────────────────────────────────────────────────────────┐
Line 512 ⟶ 514:
│ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ │
│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │
└┘└┘│└─┘└─┘│└┘└┘┐└┘└┘│└─┘└─┘│└┘└┘╷ ┐┌─┐╷┌─┐ └┘└┘│└─┘└─┘│└┘└┘ │
│ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐│ ││ │ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐ │
│ │└┘│└┘┌┘└┐└┘│└┘│├─┤├─┴┐│└┘│└┘┌┘└┐└┘│└┘│ │
│ └┐┌┘┌┐└┐┌┘┌┐└┐┌┘│ ││ │└┐┌┘┌┐└┐┌┘┌┐└┐┌┘ │
┴──────────┘└─┘└─┘└─┘└─┘└─┘└──────────┘└─┘└─┘└─┘└─┘└─┘ └┴──┴─┘└─┘└─┘└─┘└─┘└──────────┘
 
</pre>