Debian Codegraph @

texmf-dist/doc/metapost/base/source-tutorial/annulus.mp

raw
1 prologues:=3;
2
3 if scantokens(mpversion) > 1.005:
4 outputtemplate :=
5 else:
6 filenametemplate
7 fi
8 "%j-%c.mps";
9
10 verbatimtex
11 %&latex
12 \documentclass[11pt]{article}
13 \usepackage[charter]{mathdesign}
14 \usepackage[T1]{fontenc}
15 \renewcommand*{\ttdefault}{lmtt}
16 \begin{document}
17 etex
18
19 % Set unit size to 54bp = 3/4in
20 u:=54;
21
22 path p,q;
23 % Define circle of radius 3/4in
24 p:=fullcircle scaled (2*u);
25 % Define circle of radius 3/8in
26 q:=fullcircle scaled u;
27
28 beginfig(1);
29 % Fill annulus
30 fill p withcolor (3/5,4/5,1);
31 unfill q;
32
33 % Draw big circle
34 draw p;
35 % Draw small circle
36 draw q;
37 endfig;
38
39 beginfig(2);
40 % Fill annulus
41 fill p--reverse q--cycle withcolor (3/5,4/5,1);
42
43 % This loop draws arrows around the big circle
44 N:=12;
45 for n=1 upto N:
46 drawarrow subpath ((n-1)/N*length(p),n/N*length(p)) of p;
47 endfor;
48
49 % These 3 commands draw the "cut"
50 drawarrow (u,0)--(5*u/6,0);
51 draw (5*u/6,0)--(2*u/3,0);
52 drawarrow (u/2,0)--(2*u/3,0);
53
54 % This loop draws arrows around the small circle
55 for n=1 upto N:
56 drawarrow subpath ((n-1)/N*length(p),n/N*length(p)) of reverse q;
57 endfor;
58
59 % Label p and q
60 label.urt(btex \texttt{p} etex,(u/sqrt(2),u/sqrt(2)));
61 label.llft(btex \texttt{q} etex,(u/2/sqrt(2),u/2/sqrt(2)));
62 endfig;
63
64 beginfig(3);
65 % Fill annulus
66 fill p--reverse q--cycle withcolor (3/5,4/5,1);
67
68 % Draw big circle
69 draw p;
70 % Draw small circle
71 draw q;
72
73 % Above is used to determine the bbox of the annulus
74 picture h;
75 h:=currentpicture; % Store the currentpicture
76 currentpicture:=nullpicture; % Clear the currentpicture
77
78 % Create magenta background
79 fill bbox h withcolor (1,0,1);
80
81 % Fill the big circle
82 fill p withcolor (3/5,4/5,1);
83
84 % Unfill the small circle
85 unfill q;
86
87 % Draw the big circle
88 draw p;
89 % Draw the small circle
90 draw q;
91 endfig;
92 end