Koch curve: Difference between revisions

m
m (→‎{{header|Haskell}}: `where` rather than `let` for fractionally more white space)
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 lambda ab, xy: return [ab] + koch(n, (ab, xy))
return go
 
 
Line 1,170 ⟶ 1,173:
(dx, dy) = rotatedVector(theta, (a - ox, oy - b))
return (ox + dx, oy - dy)
return lambda xy, ab: go(xy, ab)
 
 
Line 1,216 ⟶ 1,219:
'''Width of square canvas -> Point list -> SVG string'''
 
def go(w, xys):
xs = ' '.join(map(
lambda xy: str(round(xy[0], 2)) + ' ' + str(round(xy[1], 2)),
Line 1,229 ⟶ 1,232:
]
)
return lambda xys: go(w, xys)
 
 
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 aan function(a f-> which[b])
function which wraps its output in a list, (using an
(using an empty list to represent computational failure).
'''
def go(xs):
return lambda xs: (''.join if isinstance(xs, str) else list)(
return chain.from_iterable(map(f, xs))
)return go
 
 
9,659

edits