lilypond-1.3.21
[lilypond.git] / mf / generic-macros.mf
blobb6b26ed9f7383beb331821496f9b23ecc26d4a33
3 % debugging
5 def test_grid =
6 if test>1:
7         proofrulethickness 1pt#;
8         makegrid(0pt,0pt for i:=-5pt step 1pt until 5pt: ,i endfor)
9                 (0pt,0pt for i:=-5pt step 1pt until 5pt: ,i endfor);
10         proofrulethickness .1pt#;
11         makegrid(0pt,0pt for i:=-4.8pt step .2pt until 4.8pt: ,i endfor)
12                 (0pt,0pt for i:=-4.8pt step .2pt until 4.8pt: ,i endfor);
14         enddef;
16 % Transforms
19 def scaledabout(expr point, scale) =
20         shifted -point scaled scale shifted point
21 enddef;
24 % Urgh! Want to do parametric types
27 def del_picture_stack=
28         save save_picture_stack, picture_stack_idx;
29 enddef;
31 % better versions of Taupin/Egler savepic cmds
34 def make_picture_stack = 
35         % override previous stack.
36         del_picture_stack;
37         picture save_picture_stack[];
38         numeric picture_stack_idx;
39         picture_stack_idx := 0;
40         def push_picture(expr p) = 
41                 save_picture_stack[picture_stack_idx] := p ;
42                 picture_stack_idx := picture_stack_idx + 1;
43         enddef;
44         def pop_picture =  save_picture_stack[decr picture_stack_idx] enddef;
45         def top_picture = save_picture_stack[picture_stack_idx] enddef;
46 enddef;
49 % save/restore pens
50 % why can't I delete individual pens?
51 def make_pen_stack =
52         del_pen_stack;
53         pen save_pen_stack[];
54         numeric pen_stack_idx;
55         pen_stack_idx := 0;
56         def push_pen(expr p) = 
57                 save_pen_stack[pen_stack_idx] := p ;
58                 pen_stack_idx := pen_stack_idx +1;
59         enddef;
60         def pop_pen =  save_pen_stack[decr pen_stack_idx] enddef;
61         def top_pen = save_pen_stack[pen_stack_idx] enddef;
62 enddef;
63 def del_pen_stack=
64         save save_pen_stack, pen_stack_idx;
65 enddef;
68 % drawing
71 % a: x diameter
72 % b: y diameter
73 % err_x: drift of y axis at top
74 % err_y: drift of x axis at right
75 def distorted_ellipse(expr a,b,err_y,err_x,super) =
76         superellipse((a,err_x),(-err_y,b),(-a,-err_x),(err_y,-b),super);
77         enddef;
79 def brush(expr a,w,b,v) =
80         begingroup;
81         save x,y;
82         z1=a; z2=b;
83         penpos3(w,angle(z2-z1)+90);
84         penpos4(w,angle(z2-z1));
85         penpos5(v,angle(z1-z2)+90);
86         penpos6(v,angle(z1-z2));
87         z3 = z4 = z1;
88         z5 = z6 = z2;
90         fill z3r{z3r-z5l}..z4l..{z5r-z3l}z3l..z5r{z5r-z3l}..z6l..{z3r-z5l}z5l..cycle;
91         penlabels(3,4,5,6);
92         endgroup;
93 enddef;
95 def draw_rounded_path(expr p, thick) =
96         push_pen(currentpen);
97         fill p;
98         pickup pencircle scaled thick;
99         draw p;
100         currentpen := pop_pen;
101 enddef;
106 def balled_crook(expr a, w, balldiam, stem) =
107 begingroup;
108         save x,y;
109         penpos1(balldiam/2,-90);
110         penpos2(balldiam/2,0);
111         penpos3(balldiam/2,90);
112         penpos4(balldiam/2,180);
113         x4r=xpart a-w; y3r=ypart a+balldiam/4;
114         x1l=x2l=x3l=x4l;
115         y1l=y2l=y3l=y4l;
116         penpos5(stem,250);
117         x5=x4r+9/8balldiam; y5r=y1r;
118         penpos6(stem,260);
119         x6l=xpart a; y6l=ypart a;
120         penstroke z1e..z2e..z3e..z4e..z1e..z5e{right}..z6e;
121         penlabels(1,2,3,4,5,6);
122 endgroup;
123 enddef;
125 def y_mirror_char =
126         currentpicture := currentpicture yscaled -1;
127         set_char_box(charbp, charwd, charht, chardp);
128 enddef;