chiark / gitweb /
Merge commit 'nc/master' into temp
[dnd] / graph.mp
1 numeric paperh, paperw;
2 numeric sqsz, hexsz;
3 numeric fine;
4 numeric margin;
5
6 paperh := 297 mm;
7 paperw := 210 mm;
8 sqsz := 5 mm;
9 hexsz := 4 mm;
10 fine := 1/4 pt;
11 margin := 20 mm;
12
13 beginfig(1);
14   numeric w, h;
15   numeric ox, oy, lx, ly;
16
17   w = floor((paperw - 2 margin)/sqsz);
18   h = floor((paperh - 2 margin)/sqsz);
19   ox = (paperw - w * sqsz)/2; lx = ox + w * sqsz;
20   oy = (paperh - h * sqsz)/2; ly = oy + h * sqsz;
21
22   pickup pencircle scaled fine;
23   for i = ox step sqsz until lx:
24     draw (i, oy) .. (i, ly);
25   endfor
26   for i = oy step sqsz until ly:
27     draw (ox, i) .. (lx, i);
28   endfor
29 endfig;
30
31 beginfig(2);
32   numeric ox, oy, lx, ly;
33   numeric w, h;
34   numeric v;
35   numeric a, b, c, d, e;
36
37   v = hexsz * sind 60;
38   w = floor((paperw - 2 margin)/(3 hexsz) - 1/2);
39   h = floor((paperh - 2 margin)/(2 v) - 1/2);
40   ox = (paperw - (w + 1/2) * 3 hexsz)/2; lx = ox + w * 3 hexsz;
41   oy = (paperh - (h + 1/2) * 2 v)/2; ly = oy + h * 2 v;
42
43   pickup pencircle scaled fine;
44   for i = ox step 3 hexsz until lx:
45     a := i + 1/2 hexsz; b := i + 2 hexsz; c := i + 3/2 hexsz;
46     for j = oy step 2 v until ly:
47       d := j + v; e := j + 2 v;
48       draw (a, e) -- (i, d) -- (a, j) -- (c, j) -- (b, d) -- (c, e);
49       if i < lx:
50         draw (b, d) -- (b + hexsz, d);
51       fi
52     endfor
53     draw (a, e) -- (c, e);
54   endfor
55 endfig;
56
57 end;