summaryrefslogtreecommitdiff
path: root/info/drawing-with-metapost/src/closed-points.mp
blob: 9abf287338dbc1c6ffc24fa92807732d042669a5 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}

vardef median primary P = 
    (origin for i=1 upto length P: + point i of P endfor) / length P
enddef;

primarydef p enlarged s = p shifted -median p scaled s shifted median p enddef;

path u, c, s;
u = unitsquare shifted -(1/2, 1/2) scaled 72;
c = fullcircle scaled 72 shifted 108 right;
s = (superellipse(right, up, left, down, 0.8)) scaled 36 shifted 216 right;

picture p[];
p1 = image(
draw origin--left scaled 50 withcolor background;
ahangle := 30; numeric r, x; r = 9/16; x = -1;
forsuffixes $=u, c, s:
  drawarrow subpath(r, r + length $) of $;
  draw fullcircle scaled 2 shifted median $ withcolor .67 red; 
  for i=0 upto length $-1: 
    fill fullcircle scaled 2 shifted point i of $ withcolor .67 red; 
    label(decimal i, point i of ($ enlarged 1.15)); 
  endfor
endfor);

p2 = image(
draw origin--left scaled 50 withcolor background;
forsuffixes $=u,c,s:
  fill median $ -- subpath (1,2) of $ -- cycle withcolor .8[blue,white];
  draw median $ -- point 1 of $;
  draw median $ -- point 2 of $;
  draw $;
endfor
);

p3 = image(
draw origin--left scaled 50 withcolor background;
forsuffixes $=u,c,s:
  r := 1/5 length $;
  fill median $ -- subpath (0,r) of $ -- cycle withcolor .8[red,white];
  draw median $ -- point 0 of $;
  draw median $ -- point r of $;
  draw $;
  endfor
);

p4 = image(
draw origin--left scaled 50 withcolor background;
forsuffixes $=u,c,s:
  fill median $ -- subpath (-1,1) of $ -- cycle withcolor .8[black,white];
  draw median $ -- point -1 of $;
  draw median $ -- point 1 of $;
  draw $;
  endfor
);

beginfig(1);
for i=1 upto 4: draw p[i] shifted (0,-108i); endfor
endfig;
\end{mplibcode}
\end{document}