% Copyright (c) Martin Geisler % You can use this MetaPost code if you find it usefull. % A macro to draw a Koch Curve. The endpoints of the curve is a and b, % and it will be of degree n: def koch(expr a, b, n) = begingroup if n = 0: draw a--b; else: koch(a, 1/3[a,b], n-1); koch(1/3[a,b], 2/3[a,b] rotatedabout(1/3[a,b], 60), n-1); koch(2/3[a,b] rotatedabout(1/3[a,b], 60), 2/3[a,b], n-1); koch(2/3[a,b], b, n-1); fi endgroup enddef; beginfig(1); pickup pencircle scaled 1pt; koch((-2.5cm, 0cm), (2.5cm, 0cm), 1); endfig; beginfig(2); pickup pencircle scaled 1pt; koch((-2.5cm, 0cm), (2.5cm, 0cm), 2); endfig; beginfig(3); pickup pencircle scaled 0.75pt; koch((-2.5cm, 0cm), (2.5cm, 0cm), 3); endfig; beginfig(4); pickup pencircle scaled 0.5pt; koch((-2.5cm, 0cm), (2.5cm, 0cm), 4); endfig; beginfig(5); pickup pencircle scaled 0.25pt; koch((-2.5cm, 0cm), (2.5cm, 0cm), 5); endfig; beginfig(6); pickup pencircle scaled 0.25pt; koch((-2.5cm, 0cm), (2.5cm, 0cm), 6); endfig; beginfig(7); numeric u; u = 6cm; koch((0u, 0u), (1u, 0u), 5); koch((1u, 0u), ((cosd(60), -sind(60))*1u), 5); koch(((cosd(60), -sind(60))*1u), (0u, 0u), 5); endfig; end.