Hilbert curve: Difference between revisions
J: implement and show ascii art.
(→{{header|Quackery}}: Added image) |
(J: implement and show ascii art.) |
||
Line 1,162:
=={{header|J}}==
Note: J's {{ }} syntax requires a recent version of J (9.02 or more recent).
<lang J>iter=: (, 1 , +@|.) @: (,~ 0j_1 ,~ 0j_1*|.)▼
asciiart=:{{
coords=. 1 3*"1 +. y % <./(,+.y)-.0
canvas=. (2+>./coords)$' '
pairs=. 2 ]\<.coords
horizontal=. =/"1 {."1 pairs
canvas=. '_' (0 1+"1<./"2 horizontal#pairs)} canvas
canvas=. '_' (0 2+"1<./"2 horizontal#pairs)} canvas
vertical=. -.horizontal
canvas=. '|' (>./"2 vertical#pairs)} canvas
}}
</lang>▼
For a graphical presentation, you could use (for example):
<lang J>require'plot'
plot hilbert 5</lang>
For asciiart, you could instead use:
▲iter=: (, 1 , +@|.) @: (,~ 0j_1 ,~ 0j_1*|.)
▲hilbert=: 3 : '0j1+(%{:) +/\0,iter ^: y '''''
__ __ __ __ __ __ __ __ __ __
▲</lang>
|__ |__| __| |__ |__| __| |__ |__|
__| __ | __ | __ |__ __| __
|__ __| | |__| |__| | |__ __| |__ __| |
__ __ | __ __ |__ __ __ __ __|
|__ |__| | |__| | __| |__ __| |__
__| __ |__ __| | __ | | __ |
|__ __| |__ __| |__ |__| |__| |__| |__|
__ __ __ __ __| __ __ __ __
|__ |__| __| |__ | |__| | | |__| |
__| __ | __ | |__ __| |__ __|
|__ __| | |__| |__| __| |__ __ __| |__
__ __ | __ __ | __ __ __ __ |
|__ |__| | |__| | |__| __| |__ |__|
__| __ |__ __| __ |__ __| __
|__ __| |__ __| |__ __| |__ __| |__ __| | </lang>
The idea is to represent the nth order hilbert curve as list of complex numbers that can be summed to trace the curve. The 0th order hilbert curve is an empty
=={{header|Java}}==
|