| 1 |
%====================================================================== |
| 2 |
% This is |
| 3 |
% chbase.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 |
|
| 23 |
% correcting the size of qs to make it a good pixelcount |
| 24 |
if .5qs <> good.x .5qs: |
| 25 |
qs:= qs if qs# * hppp > round(qs): - else: + fi 1; |
| 26 |
fi |
| 27 |
|
| 28 |
if proofing>0: input screengrid; fi; |
| 29 |
|
| 30 |
% the center of the field |
| 31 |
pair Center; Center = (qs/2,qs/2); |
| 32 |
|
| 33 |
picture BlackMan, WhiteMan, NeutralMan, OuterShape; |
| 34 |
|
| 35 |
% Some definitions for numbering the characters |
| 36 |
% the position of the relevant character in the fonttable |
| 37 |
% is calculated as sum of four offsets: |
| 38 |
% |
| 39 |
% PieceNumber + PieceColor + FieldColor + Turned |
| 40 |
% |
| 41 |
% This give the following table: |
| 42 |
% |
| 43 |
% WoW NoW BoW WoB NoB BoB |
| 44 |
% Pawn 0 6 12 18 24 30 |
| 45 |
% Knight 1 7 13 19 25 31 |
| 46 |
% Bishop 2 8 14 20 26 32 |
| 47 |
% Rook 3 9 15 21 27 33 |
| 48 |
% Queen 4 10 16 22 28 34 |
| 49 |
% King 5 11 17 23 29 35 |
| 50 |
% |
| 51 |
|
| 52 |
% Numbers of the pieces |
| 53 |
Pawn = 0; Knight = 1; Bishop = 2; Rook = 3; Queen = 4; King = 5; |
| 54 |
|
| 55 |
% Offsets for colors of the pieces |
| 56 |
White = 0; Neutral = 6; Black = 12; |
| 57 |
|
| 58 |
% Offsets for the background |
| 59 |
OnWhite = 0; OnBlack = 18; |
| 60 |
|
| 61 |
% Offsets for the turning |
| 62 |
LeftTurned = 36; RightTurned = 72; UpSideDown = 108; |
| 63 |
|
| 64 |
% Offsets for geometric figures |
| 65 |
% These figures should be point symmetric |
| 66 |
Circle = 145; |
| 67 |
Triangle = 146 |
| 68 |
Square = 147; |
| 69 |
geo1 = 148; |
| 70 |
geo2 = 149; |
| 71 |
geo3 = 150; |
| 72 |
|
| 73 |
% Offsets for geometric figures which can only be turned left |
| 74 |
% to get a realy other shape. |
| 75 |
Equihopper = 180; |
| 76 |
free1 = 181; |
| 77 |
free2 = 182; |
| 78 |
free3 = 183; |
| 79 |
free4 = 184; |
| 80 |
free5 = 185; % this is not possible, since the turned, black |
| 81 |
% on black version is over 255: 185+36+18+12 = 256!!!! |
| 82 |
|
| 83 |
% Makros for turning |
| 84 |
def TurnLeft(expr p) = |
| 85 |
p rotatedaround (Center,90); |
| 86 |
enddef; |
| 87 |
|
| 88 |
def TurnRight(expr p) = |
| 89 |
p rotatedaround (Center,-90); |
| 90 |
enddef; |
| 91 |
|
| 92 |
def TurnUpSideDown(expr p) = |
| 93 |
p rotatedaround (Center,180); |
| 94 |
enddef; |
| 95 |
|
| 96 |
% |
| 97 |
% Macros for shorten and lengthening paths |
| 98 |
% |
| 99 |
% ShortenPath: The given path is shorted at both ends, with the |
| 100 |
% real amount of pixels given |
| 101 |
% ShortenBegin, ShortenEnd: The same as above for one end only |
| 102 |
% LengthenPath: The path is elongated at both ends with a straight |
| 103 |
% line, in the direction of the path at the end |
| 104 |
% LengthenBegin, LengthenEnd: The same as above for one end only |
| 105 |
% |
| 106 |
def Perpend(expr d,p,real) = |
| 107 |
begingroup |
| 108 |
save dd; pair dd; |
| 109 |
dd = d/length(d); |
| 110 |
(p+100*(dd rotated 90) -- p+100*(dd rotated -90)) shifted (dd*real) |
| 111 |
endgroup; |
| 112 |
enddef; |
| 113 |
def ShortenPath(expr p,real) = |
| 114 |
begingroup |
| 115 |
save pa,pe; path pa,pe; |
| 116 |
pa = Perpend(direction 0 of p,point 0 of p,real); |
| 117 |
pe = Perpend(-direction length(p) of p,point length(p) of p,real); |
| 118 |
subpath ( |
| 119 |
xpart(p intersectiontimes pa), |
| 120 |
xpart(p intersectiontimes pe)) of p |
| 121 |
endgroup |
| 122 |
enddef; |
| 123 |
def ShortenBegin(expr p,real) = |
| 124 |
begingroup |
| 125 |
save pa; path pa; |
| 126 |
pa = Perpend(direction 0 of p,point 0 of p,real); |
| 127 |
subpath (xpart(p intersectiontimes pa),length(p)) of p |
| 128 |
endgroup |
| 129 |
enddef; |
| 130 |
def ShortenEnd(expr p,real) = |
| 131 |
begingroup |
| 132 |
save pe; path pe; |
| 133 |
pe = Perpend(-direction length(p) of p,point length(p) of p,real); |
| 134 |
subpath (0, xpart(p intersectiontimes pe)) of p |
| 135 |
endgroup |
| 136 |
enddef; |
| 137 |
def LengthenBegin(expr p,real) = |
| 138 |
begingroup |
| 139 |
save dd; pair dd; |
| 140 |
dd= direction 0 of p; dd:= dd/length(dd); |
| 141 |
point 0 of p - real*dd -- p |
| 142 |
endgroup |
| 143 |
enddef; |
| 144 |
def LengthenEnd(expr p,real) = |
| 145 |
begingroup |
| 146 |
save dd; pair dd; |
| 147 |
dd= direction length(p) of p; dd:= dd/length(dd); |
| 148 |
p -- point length(p) of p + real*dd |
| 149 |
endgroup |
| 150 |
enddef; |
| 151 |
def Lengthen(expr p,real) = |
| 152 |
begingroup |
| 153 |
save db; pair db; |
| 154 |
save de; pair de; |
| 155 |
db= direction 0 of p; db:= db/length(db); |
| 156 |
de= direction length(p) of p; de:= de/length(de); |
| 157 |
point 0 of p - real*db -- p -- point length(p) of p + real*de |
| 158 |
endgroup |
| 159 |
enddef; |
| 160 |
% |
| 161 |
% This macro is used by ParallelPath |
| 162 |
% |
| 163 |
def NewPoint(expr p,t,dist) = |
| 164 |
{ begingroup pair Dir; |
| 165 |
Dir= direction t of p; %show p; show t; show Dir; |
| 166 |
Dir |
| 167 |
endgroup } |
| 168 |
(point t of p + (Dir rotated 90)*(dist/length(Dir))) |
| 169 |
enddef; |
| 170 |
def xyNewPoint(expr p,t,xdist,ydist) = |
| 171 |
{ begingroup pair Dir; |
| 172 |
Dir= direction t of p; %show p; show t; show Dir; |
| 173 |
Dir |
| 174 |
endgroup } |
| 175 |
(point t of p + (cosd(angle(Dir)+90)*xdist, sind(angle(Dir)+90)*ydist)) |
| 176 |
enddef; |
| 177 |
|
| 178 |
% Macro for getting a path parallel to the given path, in distance dist |
| 179 |
% |
| 180 |
def ParallelPath(expr p,dist) = |
| 181 |
begingroup |
| 182 |
save Dir; pair Dir; Dir = direction 0 of p; |
| 183 |
|
| 184 |
((point 0 of p)+(Dir rotated 90)*(dist/length(Dir))) {Dir} |
| 185 |
for t=.5 step .5 until length(p): |
| 186 |
.. NewPoint(p,t,dist) |
| 187 |
endfor |
| 188 |
endgroup |
| 189 |
enddef; |
| 190 |
|
| 191 |
% Macro to get different distance in x and y direction |
| 192 |
% |
| 193 |
def xyParallelPath(expr p, xdist, ydist) = |
| 194 |
begingroup |
| 195 |
save Dir; pair Dir; Dir = direction 0 of p; |
| 196 |
|
| 197 |
((point 0 of p)+(cosd(angle(Dir)+90)*xdist,sind(angle(Dir)+90)*ydist)) {Dir} |
| 198 |
for t=.5 step .5 until length(p): |
| 199 |
.. xyNewPoint(p,t,xdist,ydist) |
| 200 |
endfor |
| 201 |
endgroup |
| 202 |
enddef; |
| 203 |
|
| 204 |
def DefineFootBows( |
| 205 |
% This macro depends on the values of qs and BottomSpace |
| 206 |
% and uses the makro ParallelPath. |
| 207 |
% It is used to generate the bottom bows of King, Queen and Bishop |
| 208 |
expr BottomDist, %This is the space to BottomSpace |
| 209 |
BowOneWidth, %This is the width of the main bow |
| 210 |
FootHeight, %Distance from bottom of Bow0 to top of Bow3 |
| 211 |
BowTwoLoc, %Relative location of Bow2 between Bow3 and |
| 212 |
% Bow1. 0 means position at position at Bow1, |
| 213 |
% 1.0 means position at Bow3. |
| 214 |
WidthToHeight, %Ratio of BowOneWidth/2 to Bowheight |
| 215 |
BowTwoLen, %Length of Bow2 relative to Bow1 |
| 216 |
BowThreeLen %Lenght of Bow3 relative to Bow1 |
| 217 |
) = |
| 218 |
|
| 219 |
% All parameters are in pixels when not otherwise statet. |
| 220 |
% Points are numbered from 0 to 3 from lower to upper |
| 221 |
% Points to the left have suffix l, right suffix r |
| 222 |
% points without further suffix are in the center of the bows |
| 223 |
|
| 224 |
path Bow[]; |
| 225 |
numeric BowHeight; |
| 226 |
numeric tl,tr,l[],x[]l,x[]r,x[],y[]l,y[]r,y[]; |
| 227 |
|
| 228 |
BowHeight = BowOneWidth*WidthToHeight/2; |
| 229 |
|
| 230 |
% We start with the first bow |
| 231 |
rt x1r + lft x1l = qs; x1r - x1l = BowOneWidth; |
| 232 |
y1 = BottomSpace + 2*BowHeight + BottomDist; |
| 233 |
x1 = .5qs; |
| 234 |
y1l = y1r = y1 - BowHeight; |
| 235 |
Bow1 = z1l .. {right} z1 .. z1r; |
| 236 |
|
| 237 |
z0 = z1 shifted (down*2*BowHeight); |
| 238 |
Bow0 = z1r .. {left} z0 .. z1l; |
| 239 |
|
| 240 |
Bow3= ParallelPath(Bow1,FootHeight-2*BowHeight); |
| 241 |
l3 = length(Bow3); |
| 242 |
cu:= (1-BowThreeLen)/2; |
| 243 |
Bow3:= subpath (cu*l3,(1-cu)*l3) of Bow3; |
| 244 |
z3l = point 0 of Bow3; |
| 245 |
z3 = point .5*length(Bow3) of Bow3; |
| 246 |
z3r = point infinity of Bow3; |
| 247 |
|
| 248 |
%show point 0 of reverse Bow3; |
| 249 |
%show z3r; |
| 250 |
|
| 251 |
Bow2= ParallelPath(Bow1,(FootHeight-2*BowHeight)*BowTwoLoc); |
| 252 |
l2 = length(Bow2); |
| 253 |
cu:= (1-BowTwoLen)/2; |
| 254 |
Bow2:= subpath (cu*l2,(1-cu)*l2) of Bow2; |
| 255 |
z2l = point 0 of Bow2; |
| 256 |
z2 = point .5length(Bow3) of Bow2; |
| 257 |
z2r = point infinity of Bow2; |
| 258 |
labels(1l,1,1r,2l,2r,3l,3r); |
| 259 |
enddef; |
| 260 |
% |
| 261 |
% Macro for generation the neutral piece from two pictures |
| 262 |
% given as Parameter |
| 263 |
def MakeNeutral(expr White,Black) = |
| 264 |
if unknown LeftHalft: picture LeftHalf; fi |
| 265 |
LeftHalf:= Black; |
| 266 |
cull LeftHalf keeping (1,infinity); |
| 267 |
addto LeftHalf contour (unitsquare yscaled qs xscaled (qs/2)); |
| 268 |
cull LeftHalf keeping (2,2); |
| 269 |
|
| 270 |
if unknown RightHalf: picture RightHalf; fi |
| 271 |
RightHalf:= White; |
| 272 |
cull RightHalf keeping (1,infinity); |
| 273 |
addto RightHalf contour (unitsquare yscaled qs xscaled (qs/2) shifted (qs/2,0)); |
| 274 |
cull RightHalf keeping (2,2); |
| 275 |
NeutralMan:= LeftHalf; |
| 276 |
addto NeutralMan also RightHalf; |
| 277 |
enddef; |
| 278 |
% |
| 279 |
% Makro to get a grid of real output pixels when proofing |
| 280 |
def PixelGrid(expr PixPerInch, w) = |
| 281 |
if proofing > 0: |
| 282 |
begingroup |
| 283 |
numeric d; |
| 284 |
d = pixels_per_inch/PixPerInch; |
| 285 |
makegrid(0,for i=d step d until w: ,i endfor)(0,for i=d step d until w: ,i endfor) |
| 286 |
endgroup; |
| 287 |
fi; |
| 288 |
enddef; |