summaryrefslogtreecommitdiff
path: root/info/drawing-with-metapost/src/rec-simple-tree.mp
diff options
context:
space:
mode:
Diffstat (limited to 'info/drawing-with-metapost/src/rec-simple-tree.mp')
-rw-r--r--info/drawing-with-metapost/src/rec-simple-tree.mp33
1 files changed, 33 insertions, 0 deletions
diff --git a/info/drawing-with-metapost/src/rec-simple-tree.mp b/info/drawing-with-metapost/src/rec-simple-tree.mp
new file mode 100644
index 0000000000..59657cb1b8
--- /dev/null
+++ b/info/drawing-with-metapost/src/rec-simple-tree.mp
@@ -0,0 +1,33 @@
+\documentclass[border=5mm]{standalone}
+\usepackage{luamplib}
+\usepackage{dwmpcode}
+\begin{document}
+\mplibtextextlabel{enable}
+\begin{mplibcode}
+vardef make_tree(expr level, bar) =
+ draw bar;
+ if level > 0:
+ for t=-theta, theta:
+ make_tree(level - 1, bar shifted - point 0 of bar
+ scaled r rotated t shifted point 1 of bar
+ );
+ endfor
+ fi
+enddef;
+beginfig(1);
+picture T[];
+numeric r, theta;
+r = 0.58; theta = 60; T1 = image(
+ make_tree(3, origin -- 100 up);
+ label.urt("\ $r=" & decimal r & "$, $\theta=" & decimal theta & "$", origin) withcolor \mpcolor{textred};
+);
+r := 0.75; theta := 14; T2 = image(
+ make_tree(10, origin -- 100 up);
+ label.urt("\ $r=" & decimal r & "$, $\theta=" & decimal theta & "$", origin) withcolor \mpcolor{textred};
+);
+draw T1 shifted 32 up;
+draw T2 shifted 128 right;
+endfig;
+\end{mplibcode}
+\end{document}
+