numeric paperh, paperw; numeric fine; numeric margin; paperh := 297 mm; paperw := 210 mm; fine := 1/4 pt; margin := 20 mm; numeric page; page := 0; def squares(expr hsqsz, vsqsz) = page := page + 1; beginfig(page); numeric w, h; numeric ox, oy, lx, ly; w = floor((paperw - 2 margin)/hsqsz); h = floor((paperh - 2 margin)/vsqsz); ox = (paperw - w * hsqsz)/2; lx = ox + w * hsqsz; oy = (paperh - h * vsqsz)/2; ly = oy + h * vsqsz; pickup pencircle scaled fine; for i = ox step hsqsz until lx: draw (i, oy) .. (i, ly); endfor for i = oy step vsqsz until ly: draw (ox, i) .. (lx, i); endfor endfig; enddef; def hexes(expr hexsz) = page := page + 1; beginfig(page); numeric ox, oy, lx, ly; numeric w, h; numeric v; numeric a, b, c, d, e; v = hexsz * sind 60; w = floor((paperw - 2 margin)/(3 hexsz) - 1/2); h = floor((paperh - 2 margin)/(2 v) - 1/2); ox = (paperw - (w + 1/2) * 3 hexsz)/2; lx = ox + w * 3 hexsz; oy = (paperh - (h + 1/2) * 2 v)/2; ly = oy + h * 2 v; pickup pencircle scaled fine; for i = ox step 3 hexsz until lx: a := i + 1/2 hexsz; b := i + 2 hexsz; c := i + 3/2 hexsz; for j = oy step 2 v until ly: d := j + v; e := j + 2 v; draw (a, e) -- (i, d) -- (a, j) -- (c, j) -- (b, d) -- (c, e); if i < lx: draw (b, d) -- (b + hexsz, d); fi endfor draw (a, e) -- (c, e); endfor endfig; enddef;