blob: 1a3e495f0482543d821aedec9ea17d8f4782de04 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
|