Koch curve: Difference between revisions
m
→Python :: Functional: Tidying
m (→{{header|Haskell}}: `where` rather than `let` for fractionally more white space) |
m (→Python :: Functional: Tidying) |
||
Line 1,147:
xy
]
return list(concatMap(curry(koch)(n - 1))(
zip(points, points[1:])
))
return lambda ab, xy: [ab] + koch(n, (ab, xy))▼
def go(ab, xy):
return go
Line 1,170 ⟶ 1,173:
(dx, dy) = rotatedVector(theta, (a - ox, oy - b))
return (ox + dx, oy - dy)
return
Line 1,216 ⟶ 1,219:
'''Width of square canvas -> Point list -> SVG string'''
def go(
xs = ' '.join(map(
lambda xy: str(round(xy[0], 2)) + ' ' + str(round(xy[1], 2)),
Line 1,229 ⟶ 1,232:
]
)
return
Line 1,236 ⟶ 1,239:
# concatMap :: (a -> [b]) -> [a] -> [b]
def concatMap(f):
'''A concatenated list or string over which a function f
has been mapped.
The list monad can be derived by using
function which wraps its output in a list
'''
def go(xs):
return chain.from_iterable(map(f, xs))
|