Hilbert curve: Difference between revisions
m
→Python Functional: Updated primitives. Tidied.
m (→Python Functional: Updated primitives. Tidied.) |
|||
Line 2,213:
<lang Python>'''Hilbert curve'''
from itertools import (chain, islice
Line 2,278 ⟶ 2,277:
def go(xy, tree):
r = d // 2
centres = map(▼
def
xy[0] + (r * v[0]),
xy[1] + (r * v[1])
)
centres =
return chain.from_iterable(
) if tree['nest'] else centres
return
d = w // 2
Line 2,298 ⟶ 2,297:
'''Width of square canvas -> Point list -> SVG string'''
def go(
xs = ' '.join(map(points, xys))
))▼
return '\n'.join(
['<svg xmlns="http://www.w3.org/2000/svg"',
Line 2,311 ⟶ 2,309:
]
)
return
#
def main():
'''Testing generation of the SVG for a Hilbert curve'''
Line 2,320 ⟶ 2,318:
hilbertCurve(6)
)
#
# Node :: a -> [Tree a] -> Tree a
Line 2,335 ⟶ 2,334:
def flip(f):
'''The (curried or uncurried) function f with its
arguments reversed.
▲ else:
Line 2,352 ⟶ 2,349:
yield v
v = f(v)
return
|