5 def print_penpos (suffix $) =
7 "z" & str$ & "l = (" & decimal x.$.l & ", " &decimal y.$.l & ");"
8 & " z" & str$ & "r = (" & decimal x.$.r & ", " & decimal y.$.r & ");";
14 proofrulethickness 1pt#;
17 (0pt, 0pt for i := -5pt step 1pt until 5pt: , i endfor)
18 (0pt, 0pt for i := -5pt step 1pt until 5pt: , i endfor);
20 proofrulethickness .1pt#;
23 (0pt, 0pt for i := -4.8pt step .2pt until 4.8pt: , i endfor)
24 (0pt, 0pt for i := -4.8pt step .2pt until 4.8pt: , i endfor);
30 tracingequations := tracingonline := 1;
34 def draw_staff (expr first, last, offset) =
36 pickup pencircle scaled stafflinethickness;
38 for i := first step 1 until last:
40 (i + offset) * staff_space_rounded)
42 (i + offset) * staff_space_rounded);
49 % Draw the outline of the stafflines. For fine tuning.
52 def draw_staff_outline (expr first, last, offset) =
57 pickup pencircle scaled 2;
59 for i := first step 1 until last:
61 (i + offset) * staff_space_rounded)
63 (i + offset) * staff_space_rounded);
65 draw p shifted (0, .5 stafflinethickness);
66 draw p shifted (0, -.5 stafflinethickness);
76 def scaledabout (expr point, scale) =
77 shifted -point scaled scale shifted point
82 % make a local (restored after endgroup) copy of t_var
85 def local_copy (text type, t_var) =
96 % Urgh! Want to do parametric types
99 def del_picture_stack =
100 save save_picture_stack, picture_stack_idx;
105 % better versions of Taupin/Egler savepic cmds
108 def make_picture_stack =
109 % override previous stack
111 picture save_picture_stack[];
112 numeric picture_stack_idx;
113 picture_stack_idx := 0;
115 def push_picture (expr p) =
116 save_picture_stack[picture_stack_idx] := p;
117 picture_stack_idx := picture_stack_idx + 1;
120 def pop_picture = save_picture_stack[decr picture_stack_idx] enddef;
121 def top_picture = save_picture_stack[picture_stack_idx] enddef;
127 % why can't I delete individual pens?
132 pen save_pen_stack[];
133 numeric pen_stack_idx;
135 def push_pen (expr p) =
136 save_pen_stack[pen_stack_idx] := p;
137 pen_stack_idx := pen_stack_idx + 1;
139 def pop_pen = save_pen_stack[decr pen_stack_idx] enddef;
140 def top_pen = save_pen_stack[pen_stack_idx] enddef;
145 save save_pen_stack, pen_stack_idx;
153 def soft_penstroke text t =
154 forsuffixes e = l, r:
162 ..tension1.5.. reverse path_.r
163 ..tension1.5.. cycle;
168 def soft_start_penstroke text t =
169 forsuffixes e = l, r:
178 ..tension1.5.. cycle;
183 def soft_end_penstroke text t =
184 forsuffixes e = l, r:
192 ..tension1.5.. reverse path_.r
199 % Make a round path segment going from P to Q. 2*A is the angle that the
203 def simple_serif (expr p, q, a) =
204 p{dir (angle (q - p) - a)}
205 .. q{-dir (angle (p - q) + a)}
210 % Draw an axis aligned block making sure that edges are on pixels.
213 def draw_rounded_block (expr bottom_left, top_right, roundness) =
218 % Originally, there was `floor' instead of `round', but this is
219 % not correct because pens use `round' also.
220 size = round min (roundness,
221 xpart (top_right - bottom_left),
222 ypart (top_right - bottom_left));
224 z2 + (size / 2, size / 2) = top_right;
225 z4 - (size / 2, size / 2) = bottom_left;
231 pickup pencircle scaled size;
246 def draw_block (expr bottom_left, top_right) =
247 draw_rounded_block (bottom_left, top_right, blot_diameter);
251 def draw_square_block (expr bottom_left, top_right) =
254 x1 = xpart bottom_left;
255 y1 = ypart bottom_left;
256 x2 = xpart top_right;
257 y2 = ypart top_right;
267 def draw_gridline (expr bottom_left, top_right, thickness) =
268 draw_rounded_block (bottom_left - (thickness / 2, thickness / 2),
269 top_right + (thickness / 2, thickness / 2),
274 def draw_brush (expr a, w, b, v) =
282 penpos3 (w, angle (z2 - z1) + 90);
283 penpos4 (w, angle (z2 - z1));
284 penpos5 (v, angle (z1 - z2) + 90);
285 penpos6 (v, angle (z1 - z2));
298 % Make a superellipsoid segment going from FROM to TO, with SUPERNESS.
299 % Take superness = sqrt(2)/2 to get a circle segment.
301 % See Knuth, p. 267 and p.126.
303 def super_curvelet (expr from, to, superness, dir) =
305 (superness [xpart to, xpart from],
306 superness [ypart from, ypart to]){to - from}
308 (superness [xpart from, xpart to],
309 superness [ypart to, ypart from]){to - from}
315 % Bulb with smooth inside curve.
317 % alpha = start direction
318 % beta = which side to turn to
319 % flare = diameter of the bulb
320 % line = diameter of line attachment
321 % direction = is ink on left or right side (1 or -1)
323 % Note that `currentpen' must be set correctly -- only circular pens
324 % are supported properly.
326 def flare_path (expr pos, alpha, beta, line, flare, direction) =
330 thick = pen_top + pen_bot;
334 penpos1' (line - thick, 180 + beta + alpha);
337 penpos2' (flare - thick, 180 + beta + alpha);
340 penpos3' (flare - thick, 0 + alpha);
341 rt x3'l = hround (x1'r
342 + (1/2 + 0.43) * flare * xpart dir (alpha + beta));
343 bot y2'l = vround (y1'r
344 + (1 + 0.43) * flare * ypart dir (alpha + beta));
346 rt x4' = x2'r - line * xpart dir (alpha);
347 y4' = y2'r - line * ypart dir (alpha);
349 penlabels (1', 2', 3', 4');
355 p := z1'r{dir (alpha)}
356 .. z3'r{dir (180 + alpha - beta)}
357 .. z2'l{dir (alpha + 180)}
358 .. z3'l{dir (180 + alpha + beta)}
359 ..tension t.. z4'{dir (180 + alpha + beta)}
360 .. z1'l{dir (alpha + 180)};
371 def brush (expr a, w, b, v) =
373 draw_brush (a, w, b, v);
374 penlabels (3, 4, 5, 6);
380 % Draw a (rest) crook, starting at thickness STEM in point A,
381 % ending a ball W to the left, diameter BALLDIAM.
382 % ypart of the center of the ball is BALLDIAM/4 lower than ypart A.
385 def balled_crook (expr a, w, balldiam, stem) =
389 penpos1 (balldiam / 2, -90);
390 penpos2 (balldiam / 2, 0);
391 penpos3 (balldiam / 2, 90);
392 penpos4 (balldiam / 2, 180);
395 y3r = ypart a + balldiam / 4;
396 x1l = x2l = x3l = x4l;
397 y1l = y2l = y3l = y4l;
400 x5 = x4r + 9/8 balldiam;
415 penlabels (1, 2, 3, 4, 5, 6);
421 currentpicture := currentpicture yscaled -1;
423 set_char_box (charbp, charwd, charht, chardp);
428 currentpicture := currentpicture scaled -1;
430 set_char_box (charwd, charbp, charht, chardp);
435 % center_factor: typically .5; the larger, the larger the radius of the bulb
436 % radius factor: how much the bulb curves inward
439 def draw_bulb (expr turndir, zl, zr, bulb_rad, radius_factor)=
446 ang = angle (zr - zl);
448 % don't get near infinity
449 % z0 = zr + bulb_rad * (zl - zr) / length (zr - zl);
450 z0' = zr + bulb_rad / length (zr - zl) * (zl - zr);
454 z1' = z0' + radius_factor * rad * dir (ang + turndir * 100);
455 z2' = z0' + rad * dir (ang + turndir * 300);
459 pat = zr{dir (ang + turndir * 90)}
464 % avoid grazing outlines
465 fill subpath (0, 2.5) of pat
475 % To get symmetry at low resolutions we need to shift some points and
476 % paths, but not if mf2pt1 is used.
480 vardef hfloor primary x = x enddef;
481 vardef vfloor primary y = y enddef;
482 vardef hceiling primary x = x enddef;
483 vardef vceiling primary y = y enddef;
485 vardef hfloor primary x = floor x enddef;
486 vardef vfloor primary y = (floor y.o_)_o_ enddef;
487 vardef hceiling primary x = ceiling x enddef;
488 vardef vceiling primary y = (ceiling y.o_)_o_ enddef;