summaryrefslogtreecommitdiff
path: root/info/drawing-with-metapost/src/rec-koch-steps.mp
diff options
context:
space:
mode:
Diffstat (limited to 'info/drawing-with-metapost/src/rec-koch-steps.mp')
-rw-r--r--info/drawing-with-metapost/src/rec-koch-steps.mp32
1 files changed, 32 insertions, 0 deletions
diff --git a/info/drawing-with-metapost/src/rec-koch-steps.mp b/info/drawing-with-metapost/src/rec-koch-steps.mp
new file mode 100644
index 0000000000..e696eac4f8
--- /dev/null
+++ b/info/drawing-with-metapost/src/rec-koch-steps.mp
@@ -0,0 +1,32 @@
+\documentclass[border=5mm]{standalone}
+\usepackage{luamplib}
+\begin{document}
+\mplibtextextlabel{enable}
+\begin{mplibcode}
+
+vardef koch(expr level, a, b) =
+ if level = 0:
+ a -- b
+ else:
+ save p, q, r; pair p, q, r;
+ p = 1/3[a,b]; r = 2/3[a,b]; q = r rotatedabout(p, 60);
+ koch(level-1, a, p) &
+ koch(level-1, p, q) &
+ koch(level-1, q, r) &
+ koch(level-1, r, b)
+ fi
+enddef;
+beginfig(1);
+ wd = 300;
+ for n=0 upto 4:
+ numeric y; y = -1/3 wd * n;
+ path k; k = koch(n, origin, (wd, 0)) shifted (0, y);
+ draw k withcolor 2/3 blue;
+ label.urt("\small\textsf{Level " & decimal n & "}", point infinity of k);
+ label.top("$\scriptstyle " & decimal length k & "/" & decimal arclength k & "$", (wd/2, y));
+ endfor
+
+endfig;
+\end{mplibcode}
+\end{document}
+