Hilbert curve: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a Python draft - composing pure functions.)
m (→‎Functional Python: (One addition comment for clarity, minor edit to preamble))
Line 967: Line 967:
An SVG path is serialised from the Nth application of re-write rules to a Hilbert tree structure.
An SVG path is serialised from the Nth application of re-write rules to a Hilbert tree structure.


(Save the output SVG text in a file, and load in browser, to view the Hilbert curve).
(To view the Hilbert curve, save the output SVG text in a file, and open it with a browser).


<lang Python>from itertools import (chain, islice, starmap)
<lang Python>from itertools import (chain, islice, starmap)
Line 1,024: Line 1,024:
# points :: Int -> ((Int, Int), Tree Char) -> [(Int, Int)]
# points :: Int -> ((Int, Int), Tree Char) -> [(Int, Int)]
def points(d):
def points(d):
'''Size -> subtree with its center -> All subtree points'''
def go(xy, tree):
def go(xy, tree):
r = d // 2
r = d // 2
Line 1,087: Line 1,088:
hilbertCurve(6)
hilbertCurve(6)
)</lang>
)</lang>



=={{header|Ring}}==
=={{header|Ring}}==