6 proofrulethickness 1pt#;
7 makegrid(0pt,0pt for i:=-5pt step 1pt until 5pt: ,i endfor)
8 (0pt,0pt for i:=-5pt step 1pt until 5pt: ,i endfor);
9 proofrulethickness .1pt#;
10 makegrid(0pt,0pt for i:=-4.8pt step .2pt until 4.8pt: ,i endfor)
11 (0pt,0pt for i:=-4.8pt step .2pt until 4.8pt: ,i endfor);
16 tracingequations := tracingonline := 1;
20 def draw_staff(expr first, last, offset)=
22 pickup pencircle scaled stafflinethickness;
23 for i:= first step 1 until last:
24 draw (- staff_space, (i + offset) * staff_space) .. (4 staff_space,( i+ offset)* staff_space);
30 % draw the outline of the stafflines. For fine tuning.
31 def draw_staff_outline(expr first, last, offset)=
35 pickup pencircle scaled 2;
36 for i:= first step 1 until last:
37 p := (- staff_space, (i + offset) * staff_space) .. (4 staff_space,( i+ offset)* staff_space);
39 draw p shifted (0, .5 stafflinethickness);
40 draw p shifted (0, -.5 stafflinethickness);
50 def scaledabout(expr point, scale) =
51 shifted -point scaled scale shifted point
56 % make a local (restored after endgroup) copy of t_var
58 def local_copy(text type, t_var)=
69 % Urgh! Want to do parametric types
72 def del_picture_stack=
73 save save_picture_stack, picture_stack_idx;
76 % better versions of Taupin/Egler savepic cmds
79 def make_picture_stack =
80 % override previous stack.
82 picture save_picture_stack[];
83 numeric picture_stack_idx;
84 picture_stack_idx := 0;
85 def push_picture(expr p) =
86 save_picture_stack[picture_stack_idx] := p ;
87 picture_stack_idx := picture_stack_idx + 1;
89 def pop_picture = save_picture_stack[decr picture_stack_idx] enddef;
90 def top_picture = save_picture_stack[picture_stack_idx] enddef;
95 % why can't I delete individual pens?
99 numeric pen_stack_idx;
101 def push_pen(expr p) =
102 save_pen_stack[pen_stack_idx] := p ;
103 pen_stack_idx := pen_stack_idx +1;
105 def pop_pen = save_pen_stack[decr pen_stack_idx] enddef;
106 def top_pen = save_pen_stack[pen_stack_idx] enddef;
109 save save_pen_stack, pen_stack_idx;
116 def soft_penstroke text t =
117 forsuffixes e = l,r: path_.e:=t; endfor
121 fill path_.l .. tension1.5 .. reverse path_.r .. tension1.5 .. cycle
127 % make a round path segment going from P to Q. 2*A is the angle that the
131 def simple_serif(expr p,q, a)=
132 p{dir(angle(q-p) -a)} .. q{ - dir(angle(p -q) + a)}
137 % draw an axis aligned block making sure that edges are on pixels.
140 def draw_rounded_block (expr bottom_left, top_right, roundness) =
142 round = floor min(roundness,xpart (top_right-bottom_left),
143 ypart (top_right-bottom_left));
146 pickup pencircle scaled round;
150 z2+(round/2,round/2) = top_right;
151 z4-(round/2,round/2) = bottom_left;
156 fill bot z1 .. rt z1 --- rt z2 .. top z2 ---
157 top z3 .. lft z3 --- lft z4 .. bot z4 --- cycle;
163 def draw_block (expr bottom_left, top_right) =
164 draw_rounded_block (bottom_left, top_right, blot_diameter);
167 def draw_square_block (expr bottom_left, top_right) =
169 x1 = xpart bottom_left;
170 y1 = ypart bottom_left;
171 x2 = xpart top_right;
172 y2 = ypart top_right;
175 fill (x1,y1) --- (x2,y1) --- (x2,y2) --- (x1,y2) --- cycle;
179 def draw_gridline (expr bottom_left,top_right,thickness) =
180 draw_rounded_block (bottom_left-(thickness/2,thickness/2),
181 top_right+(thickness/2,thickness/2),
186 def draw_brush(expr a,w,b,v) =
189 penpos3(w,angle(z2-z1)+90);
190 penpos4(w,angle(z2-z1));
191 penpos5(v,angle(z1-z2)+90);
192 penpos6(v,angle(z1-z2));
196 fill z3r{z3r-z5l}..z4l..{z5r-z3l}z3l..z5r{z5r-z3l}..z6l..{z3r-z5l}z5l..cycle;
202 % make a superellipsoid segment going from FROM to TO, with SUPERNESS.
203 % Take superness = sqrt(2)/2 to get a circle segment
205 % see Knuth, p. 267 and p.126
206 def super_curvelet(expr from, to, superness, dir) =
208 (superness [xpart to, xpart from], superness [ypart from,ypart to]){to - from}
210 (superness [xpart from, xpart to], superness [ypart to,ypart from]){to - from}
216 % Bulb with smooth inside curve.
218 % alpha = start direction.
219 % beta = which side to turn to.
220 % flare = diameter of the bulb
221 % line = diameter of line attachment
222 % direction = is ink on left or right side (1 or -1)
224 def flare_path(expr pos,alpha,beta,line,flare, direction) =
227 penpos1(line,180+beta+alpha);
229 penpos2(flare,180+beta+alpha);
231 penpos3(flare,0+alpha);
232 z3l=z1r+(1/2+0.43)*flare*dir(alpha+beta) ;
235 z4=z2r- line * dir(alpha);
241 p:=z1r{dir(alpha)}..z3r{dir(180+alpha-beta)}..z2l{dir(alpha+180)}
242 ..z3l{dir(180+alpha+beta)}..tension t
243 ..z4{dir(180+alpha+beta)}..z1l{dir(alpha+180)};
255 def brush(expr a,w,b,v) =
263 % Draw a (rest) crook, starting at thickness STEM in point A,
264 % ending a ball W to the left, diameter BALLDIAM
265 % ypart of the center of the ball is BALLDIAM/4 lower than ypart A
267 def balled_crook(expr a, w, balldiam, stem) =
270 penpos1(balldiam/2,-90);
271 penpos2(balldiam/2,0);
272 penpos3(balldiam/2,90);
273 penpos4(balldiam/2,180);
274 x4r=xpart a-w; y3r=ypart a+balldiam/4;
278 x5=x4r+9/8balldiam; y5r=y1r;
280 x6l=xpart a; y6l=ypart a;
281 penstroke z1e..z2e..z3e..z4e..z1e..z5e{right}..z6e;
282 penlabels(1,2,3,4,5,6);
288 currentpicture := currentpicture yscaled -1;
289 set_char_box(charbp, charwd, charht, chardp);
294 currentpicture := currentpicture scaled -1;
295 set_char_box(charwd, charbp, charht, chardp);
300 % center_factor: typically .5, the larger, the larger the radius of the bulb
301 % radius factor: how much the bulb curves inward
303 def draw_bulb(expr turndir, zl, zr, bulb_rad, radius_factor)=
310 % don't get near infinity
311 %z0 = zr + bulb_rad * (zl-zr)/length(zr -zl);
312 z0 = zr + bulb_rad /length(zr -zl) * (zl-zr);
316 z1 = z0 + radius_factor* rad * dir(ang + turndir* 100);
317 z2 = z0 + rad * dir(ang + turndir*300);
319 fill zr{dir (ang + turndir* 90)} .. z1 .. z2 -- cycle;