| 1 |
%====================================================================== |
| 2 |
% This is |
| 3 |
% blackfield.mf |
| 4 |
% |
| 5 |
% Copyright (C) 1989-93 by Elmar Bartel. |
| 6 |
% |
| 7 |
% This program is free software; you can redistribute it and/or modify |
| 8 |
% it under the terms of the GNU General Public License as published by |
| 9 |
% the Free Software Foundation; either version 1, or (at your option) |
| 10 |
% any later version. |
| 11 |
% |
| 12 |
% This program is distributed in the hope that it will be useful, |
| 13 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
% GNU General Public License for more details. |
| 16 |
% |
| 17 |
% You should have received a copy of the GNU General Public License |
| 18 |
% along with this program; if not, write to the Free Software |
| 19 |
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 |
%====================================================================== |
| 21 |
% |
| 22 |
def MakeBlackField = |
| 23 |
|
| 24 |
if unknown BlackField: |
| 25 |
|
| 26 |
pair ua[],ub[],la[],lb[],ul,lr,ma,mb; |
| 27 |
|
| 28 |
numeric n,part, penscale; |
| 29 |
|
| 30 |
if unknown HatchCount: |
| 31 |
n= 8 |
| 32 |
else: |
| 33 |
n= HatchCount |
| 34 |
fi; |
| 35 |
if unknown HatchLinePart: |
| 36 |
part= 5 |
| 37 |
else: |
| 38 |
part= HatchLinePart |
| 39 |
fi; |
| 40 |
|
| 41 |
penscale= (qs/(part*n)); |
| 42 |
% pickup pensquare scaled penscale; |
| 43 |
pickup pencircle scaled penscale; |
| 44 |
bot lft ma = (0,0); |
| 45 |
top rt mb = (w,w); |
| 46 |
draw ma--mb; |
| 47 |
|
| 48 |
top lft ul = (0,h); |
| 49 |
bot rt lr = (w,0); |
| 50 |
|
| 51 |
numeric xdelta,ydelta; |
| 52 |
xdelta= floor((xpart(lr) - xpart(ma)) / n); |
| 53 |
ydelta= floor((ypart(ul) - ypart(ma)) / n); |
| 54 |
% xdelta= floor((xpart(lr) - xpart(ma) - penscale) / n); |
| 55 |
% ydelta= floor((ypart(ul) - ypart(ma) - penscale) / n); |
| 56 |
% xdelta= floor((xpart(lr) - xpart(ma)) / (n+.5))); |
| 57 |
% ydelta= floor((ypart(ul) - ypart(ma)) / (n+.5)); |
| 58 |
|
| 59 |
% The correct loop-specification would be: |
| 60 |
% for i=1 upto n: |
| 61 |
% But it is possible (especially when the pixles per field are |
| 62 |
% below 50), that the calculated xdelta leaves ugly white space |
| 63 |
% in the corners. So we draw casually more than n hatch lines. |
| 64 |
numeric nn; |
| 65 |
nn = floor((xpart(mb))/xdelta); |
| 66 |
if nn > n: |
| 67 |
message "info: will draw " & decimal (nn-n) & " more hatch-line" |
| 68 |
if nn-n>1: & "s" fi |
| 69 |
& " in the upper corner of blackfield."; |
| 70 |
fi |
| 71 |
for i=1 upto nn: |
| 72 |
lft ua[i] = (0,ypart(ma)+(i*ydelta)); |
| 73 |
top ub[i] = (xpart(mb)-(i*xdelta),h); |
| 74 |
draw ua[i]--ub[i]; |
| 75 |
endfor; |
| 76 |
|
| 77 |
% Here the same as above... |
| 78 |
numeric nn; |
| 79 |
nn = floor((ypart(mb))/ydelta); |
| 80 |
if nn > n: |
| 81 |
message "info: will draw " & decimal (nn-n) & " more hatch-line" |
| 82 |
if nn-n>1: & "s" fi |
| 83 |
& " in the lower corner of blackfield."; |
| 84 |
fi |
| 85 |
for i=1 upto nn: |
| 86 |
bot la[i] = (xpart(ma)+(i*xdelta),0); |
| 87 |
rt lb[i] = (w,ypart(mb)-(i*ydelta)); |
| 88 |
draw la[i]--lb[i]; |
| 89 |
endfor; |
| 90 |
% This is for situations, where the the ydelta leaves |
| 91 |
% space for one more stroke in the lower right corner of the |
| 92 |
% the field. Then we do one more stroke. |
| 93 |
% It should occure very seldom. |
| 94 |
i:= n+1; |
| 95 |
bot la[i] = (xpart(ma)+(i*xdelta),0); |
| 96 |
rt lb[i] = (w,ypart(mb)-(i*ydelta)); |
| 97 |
if ypart(lb[i]) > 0: |
| 98 |
draw la[i]--lb[i]; |
| 99 |
fi; |
| 100 |
cullit; |
| 101 |
picture BlackField; |
| 102 |
BlackField:= currentpicture; |
| 103 |
|
| 104 |
else: |
| 105 |
currentpicture:= BlackField; |
| 106 |
fi; |
| 107 |
|
| 108 |
enddef; |
| 109 |
|
| 110 |
beginchar(144,qs#,qs#,0); "Empty black field"; |
| 111 |
MakeBlackField; |
| 112 |
endchar; |