create context-beginner-vi project
[cuteobr.git] / ma-cb-graphics.tex
blobe78502ba42ac758baa7e090f4b24189d05b14ea8
1 \startenvironment ma-cb-graphics
3 % We use \METAPOST\ to generate fancy shapes at run time. While
4 % typesetting this manual, \TEX\ therefore calls about
5 % 750||1000 times for \METAPOST. This kind of graphic inclusion
6 % is still under development, but at the moment already rather
7 % robust. Adding fancy shapes is a three step proces:
9 % \startopsomming[n,opelkaar]
10 % \som define a MP graphic
11 % \som call this graphic as overlay
12 % \som attach this overlay as background
13 % \stopopsomming
15 % Some graphics are reused, but the random and deeply buried
16 % ones are generated any time they're needed.
18 % When producing the PDF version, we enable object handling,
19 % a feature that is not yet implemented in a higher level
20 % command. (is now automatic)
22 % \doifmode{screen}{\useMPboxtrue}
24 % We don't use MP graphics that use fonts, so here's a time
25 % saving switch, again not meant for common users.
27 \DontUseMetaPostGraphics
29 % Some bounding box hack.
31 %\startMPinclusions
32 % input mp-tool.mp
33 %\stopMPinclusions
35 % Here are the graphics themselves. The reusable ones are
36 % saved under names specifying their dimensions and some more
37 % etc. Those shapes evolved and probably can be defined more
38 % efficient. Let it be. In some occasions we fool around with
39 % the dimensions. This is on purpose!
41 % Will be reprogrammed to use parameters ! ! ! ! ! messy now
43 \def\MPclipOne#1#2#3#4#5%
44 {\startuseMPgraphic{clip:one}
45 w := #1; width := 100; wfactor := w/width;
46 h := #2; height := 100; hfactor := h/height;
48 color lightred; lightred := (.90,.50,.50);
49 color lightgray; lightgray := (.95,.95,.95);
50 color gray; gray := (.50,.50,.50);
52 def random_delta (expr d) =
53 d-(uniformdeviate 2d)
54 enddef;
56 z1 = (0,height);
57 z2 = (0,0);
58 z3 = (width,0);
59 z4 = (width,height);
61 z5 = (width+random_delta(.2width),height+random_delta(.2height));
62 z6 = (.5width+random_delta(.1width),height+random_delta(.1height));
64 pickup pencircle
65 xscaled (#3/wfactor)
66 yscaled (#3/(2*hfactor))
67 rotated 30;
69 draw z5..z1..z2..z3..z4..z6 withcolor #4;
71 pickup pencircle
72 xscaled (#3/wfactor)
73 yscaled (#3/hfactor);
75 draw z1 withcolor #5;
76 draw z2 withcolor #5;
77 draw z3 withcolor #5;
78 draw z4 withcolor #5;
79 draw z5 withcolor #5;
80 draw z6 withcolor #5;
82 newwidth := (xpart (urcorner currentpicture)) -
83 (xpart (llcorner currentpicture));
84 newheight := (ypart (urcorner currentpicture)) -
85 (ypart (llcorner currentpicture));
87 currentpicture := currentpicture
88 xscaled (w/newwidth) yscaled (h/newheight);
89 \stopuseMPgraphic
90 \useMPgraphic{clip:one}{}}
92 \def\MPclipTwo#1#2#3#4#5#6% \unexpanded goes wrong in etex!
93 {delta := #3;
94 width := #1-delta;
95 height := #2-delta;
97 color lightred; lightred := (.90,.50,.50);
98 color lightgray; lightgray := (.95,.95,.95);
99 color gray; gray := (.50,.50,.50);
101 vardef gamma =
102 g := #4; ((g/3) + (uniformdeviate (2g/3)))
103 enddef;
105 z1 = (0,0);
106 z2 = (width,0);
107 z3 = (width,height);
108 z4 = (0,height);
110 x12= .5[x1,x2]; y12=y1+gamma;
111 y23= .5[y2,y3]; x23=x2-gamma;
112 x34= .5[x3,x4]; y34=y3-gamma;
113 y41= .5[y4,y1]; x41=x4+gamma;
115 pickup pencircle
116 xscaled delta
117 yscaled .5delta
118 rotated 30;
120 path p;
121 p := z1..z12..z2 &
122 z2..z23..z3 &
123 z3..z34..z4 &
124 z4..z41..z1 & cycle;
125 fill p withcolor #6;
126 draw p withcolor #5;}
128 \def\MPclipTwoA#1#2#3#4#5#6%
129 {\startreusableMPgraphic{clip:twoA:#1#2#3}{}
130 \MPclipTwo{#1}{#2}{#3}{#4}{#5}{#6}%
131 \stopreusableMPgraphic
132 \reuseMPgraphic{clip:twoA:#1#2#3}{}}
134 \def\MPclipTwoB#1#2#3#4#5#6%
135 {\startuseMPgraphic{clip:twoB}{}
136 \MPclipTwo{#1}{#2}{#3}{#4}{#5}{#6}%
137 \stopuseMPgraphic
138 \useMPgraphic{clip:twoB}{}}
140 \def\MPclipThree#1#2% no reuse here, due to pre-processing
141 {\startuseMPgraphic{clip:three}{}
143 delta := #2;
144 width := #1-delta;
146 z1 = (0,0);
147 z2 = (width,0);
149 pickup pencircle
150 scaled delta;
152 draw z1--z2 withcolor (.5,.5,.5);
154 pickup pencircle
155 scaled 3delta;
157 draw z1 withcolor green;
158 draw z2 withcolor green;
160 \stopuseMPgraphic
161 \useMPgraphic{clip:three}{}}
163 \def\MPclipFourR#1#2#3%
164 {\startreusableMPgraphic{clip:fourR:#1#2#3}{}
166 delta := #3;
167 width := #1-delta;
168 height := (#2-delta)/3;
170 z1 = (0,3height);
171 z2 = (0,2height);
172 z3 = (width,1.5height);
173 z4 = (0,height);
174 z5 = (0,0);
176 pickup pencircle
177 xscaled delta
178 yscaled .5delta
179 rotated 30;
181 draw z1--z2{up}..z3..{up}z4--z5 withcolor (.5,.5,.5);
183 pickup pencircle
184 scaled delta;
186 draw z1 withcolor red;
187 draw z2 withcolor red;
188 draw z3 withcolor red;
189 draw z4 withcolor red;
190 draw z5 withcolor red;
192 \stopreusableMPgraphic
193 \reuseMPgraphic{clip:fourR:#1#2#3}{}}
195 \def\MPclipFourL#1#2#3%
196 {\startreusableMPgraphic{clip:fourL:#1#2#3}{}
198 delta := #3;
199 width := #1-delta;
200 height := (#2-delta)/3;
202 z1 = (0,3height);
203 z2 = (0,2height);
204 z3 = (-width,1.5height);
205 z4 = (0,height);
206 z5 = (0,0);
208 pickup pencircle
209 xscaled delta
210 yscaled .5delta
211 rotated 30;
213 draw z1--z2{up}..z3..{up}z4--z5 withcolor (.5,.5,.5);
215 pickup pencircle
216 scaled delta;
218 draw z1 withcolor red;
219 draw z2 withcolor red;
220 draw z3 withcolor red;
221 draw z4 withcolor red;
222 draw z5 withcolor red;
224 \stopreusableMPgraphic
225 \reuseMPgraphic{clip:fourL:#1#2#3}{}}
227 \def\MPclipFive#1#2#3#4%
228 {\startreusableMPgraphic{clip:five:#1#2#3#4}{}
230 delta := #4;
231 width := #1-delta;
232 height := #2-delta;
233 lines := #3;
235 z1 = (0,0);
236 z2 = (lines,0);
237 z3 = (.5width,height);
238 z4 = (width-lines,0);
239 z5 = (width,0);
241 pickup pencircle
242 xscaled delta
243 yscaled .5delta
244 rotated 30;
246 draw z1--z2{dir 135}...z3...{dir -135}z4--z5 withcolor (.5,.5,.5);
248 pickup pencircle
249 scaled delta;
251 draw z1 withcolor red;
252 draw z2 withcolor red;
253 draw z3 withcolor red;
254 draw z4 withcolor red;
255 draw z5 withcolor red;
257 \stopreusableMPgraphic
258 \reuseMPgraphic{clip:five:#1#2#3#4}{}}
260 \def\MPclipSix#1#2%
261 {\startreusableMPgraphic{clip:six:#1#2}{}
263 delta := #2;
264 height := #1-delta;
266 color green; green := (.1,.8,.1);
268 z1 = (0,0);
269 z2 = (0,height);
271 pickup pencircle
272 scaled delta;
274 draw z1--z2 withcolor (.5,.5,.5);
276 pickup pencircle
277 scaled 3delta;
279 draw z1 withcolor green;
280 draw z2 withcolor green;
282 \stopreusableMPgraphic
283 \reuseMPgraphic{clip:six:#1#2}{}}
285 \def\MPclipSeven#1#2#3%
286 {\startreusableMPgraphic{clip:seven:#1#2}{}
288 width := #1;
289 height := #2;
290 delta := #3;
292 color green; green := (.1,.8,.1);
294 x1 = x4 = 0; x2 = x3 = width;
295 y1 = y2 = 0; y3 = y4 = height;
297 pickup pencircle
298 scaled delta;
300 draw z1--z2--z3--z4--cycle withcolor (.5,.5,.5);
302 pickup pencircle
303 scaled 3delta;
305 draw z1 withcolor green;
306 draw z2 withcolor green;
307 draw z3 withcolor green;
308 draw z4 withcolor green;
310 \stopreusableMPgraphic
311 \reuseMPgraphic{clip:seven:#1#2}{}}
313 \stopenvironment