Anonymous user
Hilbert curve: Difference between revisions
Completed ASCII line drawing with turnarounds
m (→{{header|Lua}}) |
(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
<pre>
┌─────────────────────────────────────────────────────────┐
Line 512 ⟶ 514:
│ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ ┌┘└┐└┘┌┘└┐└┘┌┘└┐ │
│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │┌┐│┌┐└┐┌┘┌┐│┌┐│ │
│
│ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐│ ││ │ ┌┐┌┐│┌─┐┌─┐│┌┐┌┐ │
│ │└┘│└┘┌┘└┐└┘│└┘│├─┤├─┴┐│└┘│└┘┌┘└┐└┘│└┘│ │
│ └┐┌┘┌┐└┐┌┘┌┐└┐┌┘│ ││ │└┐┌┘┌┐└┐┌┘┌┐└┐┌┘ │
</pre>
|