\def\Version{2025-09-11}

\setupinteraction[
  title={ConTeXt 蹊径},
  author={李延瑞 (lyr.m2@live.cn)},
  keyword={TeX, ConTeXt LMTX, LuaMetaTeX}
]

% 封面
\startMPinclusions[+]
vardef hilbert(expr sidelength, n) = 
  numeric u; u := 0.5sidelength;
  pair a, b, c, d;
  a := (-0.5, -0.5) * u;
  b := (-0.5, 0.5) * u;
  c := (0.5, 0.5) * u;
  d := (0.5, -0.5) * u;
  path p; 
  p := a -- b -- c -- d;
  transform sw, nw, ne, se;
  sw := identity
        scaled 0.5
        reflectedabout ((0, 0), (1, 1))
        shifted (-0.5u, -0.5u);
  nw := identity
        scaled 0.5
        shifted (-0.5u, 0.5u);
  ne := identity
        scaled 0.5
        shifted (0.5u, 0.5u);
  se := identity
        scaled 0.5
        reflectedabout ((0, 0), (1, -1))
        shifted (0.5u, -0.5u);

  for i := 2 upto n:
    p := p transformed sw for j := nw, ne, se: -- p transformed j endfor;
  endfor;
  p
enddef;
\stopMPinclusions

\startuseMPgraphic{TitleGraphic}
path p, q;
p := hilbert(OverlayWidth, 5) yscaled(OverlayHeight / OverlayWidth);
p := p randomized 2pt;

numeric u, n; u := 5cm; n := (arclength p) / u;
pickup pencircle scaled 2pt;
for i = 1 upto n:
  q := p cutafter (point u on p);
  p := p cutbefore (point u on p);
  draw q withcolor .5[white randomized (1, 1, 1), white];
endfor;
draw p withcolor white randomized (1, 1, 1);
\stopuseMPgraphic
\defineoverlay[TitleGraphic][\useMPgraphic{TitleGraphic}]

%% 阴影盒
\startuniqueMPgraphic{shade box}
numeric u, w, h, roundcorner, offset;
path p, q;
color shade;
u := 1cm; w := \overlaywidth; h := \overlayheight;
p := unitsquare xyscaled (w, h);
offset := 7pt;
shade := darkgray;
pickup pencircle scaled 8pt;
for i = 0 step .1 until 1:
    q := unitsquare xyscaled (w, h) shifted (i * offset, -i * offset);
    fill q withcolor transparent (1, .1, shade);
    draw q withcolor transparent (1, .1, shade);
endfor;
q := p shifted (-offset, offset);
fill p withcolor transparent(8, .5, \MPcolor{dimgray});
draw p withcolor \MPcolor{lightsteelblue};
\stopuniqueMPgraphic
\defineoverlay[shade box][\uniqueMPgraphic{shade box}]
\defineframed[coverbox][frame=off,background={shade box}]

\defineoverlay[bgimage][{\externalfigure[w.png][width=\overlaywidth, height=\overlayheight]}]

\setupbackgrounds[page][background=TitleGraphic]
\startstandardmakeup
\hfil
  \startcolor[yellow]
    \coverbox[width=.8\textwidth,height=6cm]{
      {\switchtobodyfont[ss,32pt]{\CONTEXT\, 蹊径}}
      \blank[1cm]
      \start
      \switchtobodyfont[ss,16pt]
      \midaligned{\hbox{李延瑞}}
      \blank[5mm]
      \Version
      \stop
    }
  \stopcolor
  \hfil
  \blank[14cm]
\stopstandardmakeup
\setupbackgrounds[page][background=]
