%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: clock.mf
% Date: April 10, 2001
% Author: Oliver Corff
% (c) 2001 Ulaanbaatar, Beijing, Berlin
%
% A metafont for providing the clock to LaTeX-users.
%
% Usage: see package clock 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% This font contains characters for hands and dials. %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

mode_setup;
	mg:=4/4;
	thin#:=mg*1pt#;
	width#:=mg*16pt#;
	height#:=mg*12pt#;
	depth#:=mg*4pt#;
	margin#:=mg*1.05pt#;

	define_pixels(width,height,depth,thin,margin);

	font_size = 10pt#;

	font_x_height = 16pt#;
	% font_quad = 16pt#;
	font_normal_space = 0pt#;
	font_extra_space = 0pt#;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% All sorts of clock parts
%
def MinuteHand (expr minutes) =	% Minutenzeiger
	z1=(w/2,1/2(h-d));
	z2=(w/2,27/36h-margin);
	pickup pencircle scaled 1/2thin; % rotated (-minutes*6);
	draw (z1--z2) rotatedabout (z1,-minutes*6);
enddef;

def HourHand (expr minutes) =	% Stundenzeiger
	z1=(w/2,1/2(h-d));
	z2=(w/2,24/36h-margin);
	pickup pencircle scaled 9/16thin; % rotated (-minutes*6);
	draw (z1--z2) rotatedabout (z1,-minutes*6);
enddef;

def Hands (expr minutes) =	% Beide Zeiger
	%
	beginchar(minutes+64,width#,height#,depth#);
		MinuteHand(minutes);
	endchar;
	%
	beginchar(minutes+128,width#,height#,depth#);
		HourHand(minutes);
	endchar;
enddef;

def NESW =
	% This routine places ticks at 12, 3, 6 and 9 o'clock
	for l = 0,3,6,9:
		top z5=(w/2,h-margin);
		    z7=(w/2,1/2(h-d));
		    z6=6/36[z5,z7];
		draw (z5--z6) rotatedabout (z7,-l*30);
	endfor;
enddef;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% All sorts of dials
%
beginchar("0",width#,height#,depth#);
	top z1=(0.5w,h-margin);		% 12 Uhr
	rt  z2=(w-margin,0.5(h-d)); 	%  3 Uhr
	bot z3=(x1,-d+margin);		%  6 Uhr
	lft z4=(0+margin,y2);		%  9 Uhr
	
	pickup pencircle scaled 1/2thin;
	draw z1...z2...z3...z4...cycle;
endchar;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
beginchar("1",width#,height#,depth#);
	%
	% "Standard", or "Classical" dial
	% with indications for every hour
	%
	pickup pencircle scaled 5/8thin;
	NESW;

	pickup pencircle scaled 2/4thin;
	for l = 1,2,4,5,7,8,10,11:
		numeric x[];
		numeric y[];
		top z5=(w/2,h-margin);
		    z7=(w/2,1/2(h-d));
		    z6=3/36[z5,z7];
		draw (z5--z6) rotatedabout (z7,-l*30);
	endfor;
endchar;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
beginchar("2",width#,height#,depth#);
	%
	% A rather minimalist dial, with
	% just a dot marking each hour
	%
	pickup pencircle scaled 2/4thin;
	for l = 0 step 1 until 11:
		top z2=(w/2,h-margin-6/8thin);
		    z1=(w/2,1/2(h-d));
		drawdot(z2) rotatedabout (z1,-l*30);
	endfor;
endchar;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
beginchar("3",width#,height#,depth#);
	% A radically minimalist dial
	pickup pencircle scaled 5/8thin;
	NESW;
endchar;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The true center of activity:
% create both hands at the same time
%
for minutes = 0 step 1 until 59:
	Hands(minutes);
endfor;
end.