Hilbert curve: Difference between revisions

Content added Content deleted
(Completed ASCII line drawing with turnarounds)
Line 403: Line 403:


Lindenmayer:
Lindenmayer:

A,B are Lindenmayer AXIOMS
* A,B are Lindenmayer AXIOMS


Line drawing:
Line drawing:

+,- turn right, left
* +,- turn right, left
F draw line forward
* F draw line forward
<num> repeat the following draw command <num> times
* <num> repeat the following draw command <num> times
<any> move on canvas without drawing
* <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
<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
local bit=bit32 or bit -- Lua 5.2/5.3 compatibilty
Line 439: Line 441:
function draw(s)
function draw(s)
local char={
local char={
{"─","┘","┐",}, -- r
{"─","┘","╴","┐",}, -- r
{"│","┐","┌",}, -- up
{"│","┐","╷","┌",}, -- up
{"─","┌","└",}, -- l
{"─","┌","╶","└",}, -- l
{"│","└","┘",}, -- down
{"│","└","╵","┘",}, -- down
}
}
local scr={}
local scr={}
Line 498: Line 500:
draw(str:hilbert(n))
draw(str:hilbert(n))
</lang>
</lang>
{{output}} luajit hilbert.lua 4 10FAF-4F2+2F-2F-2F++4F-F-4F+2F+2F+2F++3F+2F+3F--4FA10F-16F-58F-16F-
{{output}} luajit hilbert.lua 4 1M9FAF-4F2+2F-2F-2F++4F-F-4F+2F+2F+2F++3F+2F+3F--4FA10F-16F-58F-16F-
<pre>
<pre>
┌─────────────────────────────────────────────────────────┐
┌─────────────────────────────────────────────────────────┐
Line 512: Line 514:
│ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ │
│ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ │
│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │
│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │
└┘└┘│└─┘└─┘│└┘└┘┐ ┐┌─┐ └┘└┘│└─┘└─┘│└┘└┘ │
└┘└┘│└─┘└─┘│└┘└┘╷ ╷┌─┐ └┘└┘│└─┘└─┘│└┘└┘ │
│ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐│ ││ │ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐ │
│ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐│ ││ │ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐ │
│ │└┘│└┘┌┘└┐└┘│└┘│├─┤├─┴┐│└┘│└┘┌┘└┐└┘│└┘│ │
│ │└┘│└┘┌┘└┐└┘│└┘│├─┤├─┴┐│└┘│└┘┌┘└┐└┘│└┘│ │
│ └┐┌┘┌┐└┐┌┘┌┐└┐┌┘│ ││ │└┐┌┘┌┐└┐┌┘┌┐└┐┌┘ │
│ └┐┌┘┌┐└┐┌┘┌┐└┐┌┘│ ││ │└┐┌┘┌┐└┐┌┘┌┐└┐┌┘ │
┴──────────┘└─┘└─┘└─┘└─┘└─┘ └┴──┴─┘└─┘└─┘└─┘└─┘└──────────┘
└──────────┘└─┘└─┘└─┘└─┘└─┘ └┴──┴─┘└─┘└─┘└─┘└─┘└──────────┘

</pre>
</pre>