summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/4-1-18.mp
blob: 3b85dcc2353edeed676ac1d2fd70a34ab7bedd77 (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
% --- start of displayed preamble in the book ---
% tdraw and trotate as defined above
% --- end of displayed preamble in the book ---

pair _cp; % current point
_cp=(0,0);
numeric _tdir; % turtle direction
_tdir=0;

def tdraw(expr d) text options=
  draw _cp--(_cp+d*dir(_tdir)) options;
  _cp:=_cp+d*dir(_tdir);
enddef;

def trotate(expr a)=
  _tdir:=_tdir+a;
enddef;

defaultfont:="ptmr8r";
warningcheck:=0;
beginfig(1)
numeric u; u=4cm;
for i=1 upto 10:
  tdraw(.1u); trotate(18);
endfor;
trotate(90); tdraw(.5u); trotate(90); tdraw(.5u);
trotate(45); tdraw(.5u); trotate(135); tdraw(1u);
endfig;
end;