summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/4-1-19.mp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /info/examples/lgc2/4-1-19.mp
Initial commit
Diffstat (limited to 'info/examples/lgc2/4-1-19.mp')
-rw-r--r--info/examples/lgc2/4-1-19.mp41
1 files changed, 41 insertions, 0 deletions
diff --git a/info/examples/lgc2/4-1-19.mp b/info/examples/lgc2/4-1-19.mp
new file mode 100644
index 0000000000..1a3e495f04
--- /dev/null
+++ b/info/examples/lgc2/4-1-19.mp
@@ -0,0 +1,41 @@
+% --- start of displayed preamble in the book ---
+pair _cp; % current point
+pair _cps[]; % stack of current points
+numeric _ncps; _ncps=0;
+
+def PUSH = _cps[_ncps]:=_cp; _ncps:=_ncps+1; enddef;
+def POP =
+ if _ncps>0: _ncps:=_ncps-1; _cp:=_cps[_ncps];
+ else: message "YOU CAN'T POP HERE"; stophere
+ fi;
+enddef;
+
+def initdrawing=_cp:=origin; enddef;
+def mv(expr d,a)=_cp:=_cp+d*dir(a);enddef;
+def lineto(expr d,a) text options=
+ draw _cp--(_cp+d*dir(a)) options;mv(d,a);enddef;
+
+def mvright(expr d)=mv(d,0);enddef;
+def mvleft(expr d)=mvright(-d);enddef;
+def mvup(expr d)=mv(d,90);enddef;
+def mvdown(expr d)=mvup(-d);enddef;
+def lineright(expr d) text options=lineto(d,0) options;enddef;
+def lineleft(expr d) text options=lineright(-d) options;enddef;
+def lineup(expr d) text options=lineto(d,90) options;enddef;
+def linedown(expr d) text options=lineup(-d) options;enddef;
+% --- end of displayed preamble in the book ---
+defaultfont:="ptmr8r";
+warningcheck:=0;
+beginfig(1)
+numeric u; u=1cm;
+initdrawing;
+lineright(3u);lineup(2u);
+PUSH
+ lineto(1.5u/cosd(30),150);
+ lineto(1.5u/cosd(30),210);
+POP
+lineleft(3u);linedown(2u);
+mvright(u);
+lineup(1.5u);lineright(u);linedown(1.5u);
+endfig;
+end;