Hilbert curve: Difference between revisions
Content added Content deleted
(→{{header|Quackery}}: Added image) |
(J: implement and show ascii art.) |
||
Line 1,162: | Line 1,162: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Note: J's {{ }} syntax requires a recent version of J (9.02 or more recent). |
|||
⚫ | |||
⚫ | |||
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 |
|||
}} |
|||
⚫ | |||
For a graphical presentation, you could use (for example): |
|||
<lang J>require'plot' |
<lang J>require'plot' |
||
plot hilbert 5</lang> |
|||
For asciiart, you could instead use: |
|||
⚫ | |||
⚫ | |||
<lang J> asciiart hilbert 4 |
|||
__ __ __ __ __ __ __ __ __ __ |
|||
⚫ | |||
|__ |__| __| |__ |__| __| |__ |__| |
|||
__| __ | __ | __ |__ __| __ |
|||
|__ __| | |__| |__| | |__ __| |__ __| | |
|||
__ __ | __ __ |__ __ __ __ __| |
|||
|__ |__| | |__| | __| |__ __| |__ |
|||
__| __ |__ __| | __ | | __ | |
|||
|__ __| |__ __| |__ |__| |__| |__| |__| |
|||
__ __ __ __ __| __ __ __ __ |
|||
|__ |__| __| |__ | |__| | | |__| | |
|||
__| __ | __ | |__ __| |__ __| |
|||
|__ __| | |__| |__| __| |__ __ __| |__ |
|||
__ __ | __ __ | __ __ __ __ | |
|||
|__ |__| | |__| | |__| __| |__ |__| |
|||
__| __ |__ __| __ |__ __| __ |
|||
|__ __| |__ __| |__ __| |__ __| |__ __| | </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 |
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 list. The first half of the n+1 the curve is formed by rotating the nth right by 90 degrees and reversing, appending -i and appending the nth curve. The whole n+1th curve is the first half appended to 1 appended to the conjugate of the reverse of the first half. |
||
=={{header|Java}}== |
=={{header|Java}}== |