summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/fonts/chess/chessdiag.Xmf
blob: 1023accfcbdeb40c0cc745fba4823a018f2e15f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
% This is `chessdiag.mf' version 1.2 as of 10/91
% METAfounded by Piet Tutelaers (internet: rcpt@urc.tue.nl)

% file generates a complete chess diagram in a X-window

% most versions of METAFONT have memorylimits so generating a complete
% diagram of 160 X 160 points for a 300 DPI printer is not possible

mode_setup;
input chessbase;

def draw_pieces(text piece_list) = 
   string piece, location;
   for p=piece_list:
      l:=length p;
      exitunless (l=2) or (l=3);
      if l=2: piece:="p"; i:=0;
      else: piece:=substring(0,1) of p; i:=1; fi;
      column:=ASCII substring(i,i+1) of p - ASCII "a";
      row:=ASCII substring(i+1,i+2) of p - ASCII "1";
      if not odd(column+row): background:=dark; else: background:=light; fi;
      scantokens piece(d, column,row);
      endfor;
   enddef;
   
def w(text piece_list) = 
   color:=white;
   empty_board(d); draw_pieces(piece_list);
   enddef;
   
def b(text piece_list) = 
   color:=black;
   draw_pieces(piece_list);
   enddef;
   
M=8; % number of squares
d#:=100pt#/M; % size per square
fine#:=1/100*d#; thin#:=1/90*d#; thick#:=1/36*d#; border#:=1/20*d#;
define_blacker_pixels(fine, thin, thick, border);
define_whole_pixels(d);
pickup pencircle scaled fine; fine_pen:=savepen ; % for drawing dark squares
pickup pencircle scaled border; border_pen:=savepen ; % for border ofboard
pickup pencircle scaled thin; thin_pen:=savepen ; % for drawing pieces
pickup pencircle scaled thick; thick_pen:=savepen; % for drawing inside pieces
light=0; dark=1; white=0; black=1;

% put here the wanted diagram (ex.: mate in three problem)

w("Kc2","Nb4","Bf8","b3","g7");
b("Ka3","b6");

% Next function draws the picture on the screen (Showit is derived from
% showit in plain.mf). The value of screen_rows is redefined because
% otherwise the MF-picture will be truncated. To fit the picture in a
% X-window the next geometry definition in ~/.Xdefaults is assumed:
% 
%	Metafont*geometry:      500x500+200+200
%
% This geometry together with the offset (-40, 460) in the line
% furtheron did the job on my NCD16 X-terminal! Perhaps you need to fiddle
% with the constants to get it right for your display.
screen_rows:=500;
def Openit = openwindow currentwindow
 from origin to (screen_rows,screen_cols) at (-40,460) enddef;
 def Showit = Openit; let Showit=Showit_; Showit enddef; % first time only
 def Showit_ = display currentpicture inwindow currentwindow enddef;

Showit;

message("White mates in three moves. Do you see how?");
StopMe;

end;