%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: clock.tex
% Date: April 10, 2001
% Author: Oliver Corff
% (c) 2001 Ulaanbaatar, Macau, Berlin
%
% A package for providing graphical
% clocks to TeX- and LaTeX-users.
%
% Usage: \input clock
%
% No options.
%
% NB: This file does not require LaTeX2e!
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Size definitions
%
\ifx\LaTeXclock\undefined
	\font\myclockfont clock
	\font\mybigclockfont clock at 24pt
	%
	\def\clockfont{\let\clockfont\myclockfont}
	\def\bigclockfont{\let\clockfont\mybigclockfont}
\fi

\ifx\TeXclock\undefined
	\def\TeXclock{}
	\catcode`@ 11
\else
	\endinput
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Variables
%
	\newcount\time@in@minutes
	\newcount\floor@minutes
	\newcount\hour@minutes
	\newcount\text@hours
	\newcount\text@minutes
	\newcount\my@minute
	\newcount\my@minutes
	\newcount\my@hour
	\newcount\ClockStyle		% one of 1 2 3 4
	\global\newif\ifClockFrame	% one of true false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Time Calculations
%
\def\calc@hours{%
	\time@in@minutes=\time
	\text@hours=\time@in@minutes
	\divide\text@hours by 60 }

\def\texthours{%
	\calc@hours
	\the\text@hours }

\def\calc@minutes{%
	\calc@hours
	\floor@minutes=\text@hours
	\multiply\floor@minutes by 60
	\text@minutes=\time@in@minutes
	\advance\text@minutes-\floor@minutes }

\def\textminutes{%
	\calc@minutes
	\ifnum\text@minutes<10 0\fi
	\the\text@minutes}

\def\texttime{\texthours:\textminutes}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Display Operations
%
\def\show@clock#1#2{%
	{\clockfont %
	\char#1\kern-1.00ex \char#2%	% Print hours and minutes!
	\advance\ClockStyle by 48	% Build dial
	\ifnum\ClockStyle>48
		\kern-1ex\char\ClockStyle %
	\fi
	\ifClockFrame \kern-1ex\char48 \fi
	}}

\def\calc@movement{%
	\ifnum\my@hour>11 \advance\my@hour by -12 \fi
	\multiply\my@hour by 5
	\my@minutes=\my@minute
	\divide\my@minutes by 12
	\advance\my@hour by \my@minutes
	\advance\my@hour by 128
	\advance \my@minute by 64
	}

\def\clock#1#2{%
	\my@hour#1\my@minute#2%
	\calc@movement
	\show@clock{\my@hour}{\my@minute}}


\def\clocktime{%
	\calc@minutes % Calls \calc@hours
	\clock{\text@hours}{\text@minutes}
	}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Initial Settings
%
\ClockStyle=1
\ClockFramefalse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Some Housekeeping...
%
\ifx\LaTeXclock\undefined
	\catcode`@ 12
\fi
