# Generate analog clock with numbered face

I'm trying to generate a clock similar to as in the question asked here

But I want the face to be numbered. Is this possible with this package or any other?

-
As an aside -- if you're planning on producing a Roman Numeral clock, be careful to look at actual RN clocks, as they sometimes have interesting features, e.g., most show 4 as "IIII" instead of "IV", and most also have the "feet" of each number pointing towards the center of the clock (making the six upside down). –  Chris Gregg Sep 9 '13 at 6:09

A little variation of an example taken from the PGF documentation (Section 83 Repeating Things: The Foreach Statement, page 912 for version 3.0):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[line cap=rect,line width=3pt]
\foreach \angle [count=\xi] in {60,30,...,-270}
{
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\node[font=\large] at (\angle:1.36cm) {\textsf{\xi}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:1.6cm) -- (\angle:2cm);
\draw (0,0) -- (120:0.8cm);
\draw (0,0) -- (90:1cm);
\end{tikzpicture}

\end{document}


An perhaps one could define a command to control some attributes; below an example, allowing to specify the color, the radius and the font size for the numbers:

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}

\NewDocumentCommand{\Clock}{O{2cm}O{\large}O{cyan}}{%
\foreach \angle [count=\xi] in {60,30,...,-270}
{
}
\foreach \angle in {0,90,180,270}
\end{tikzpicture}%
}

\begin{document}

\end{document}


-
Do you know if this example has been removed from the documentation? I can't see anything obviously relevant on page 507... –  cfr Jul 27 at 0:12
@cfr It was page 507 on the manual for version 2.10. For version 3.0 it was moved to page 912. I've edited my answer updating the page and adding the name of the section in the hope of a more "stable" reference. –  Gonzalo Medina Jul 27 at 0:28
Thanks! I assumed that was the case and hoped you might do something like that. –  cfr Jul 27 at 1:12

We can convert Gonzalo's excellent answer in to a macro so that we can use it like:

\clock{<hour>}{<minute>}{<seconds>}


Further beautification is possible and left as a home work ;-).

\documentclass[dvipsnames]{article}
\usepackage{tikz}

\begin{document}
\newcommand\clock[3]{%
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=Goldenrod!30] (0,0) circle (2cm);
\foreach \angle / \label in
{0/3, 30/2, 60/1, 90/12, 120/11, 150/10, 180/9,
210/8, 240/7, 270/6, 300/5, 330/4}
{
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:1.6cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,.9cm) {TICK-TOCK};
\draw[rotate=90,line width=2pt] (0,0) -- (-#1*30-#2*30/60:0.7cm); % hours
\draw[rotate=90,line width=1.5pt] (0,0) -- (-#2*6:1cm); % minutes
\draw[rotate=90,thin,red] (0,0) -- (-#3*6:1.2cm); % seconds
\path [fill=red] (0,0) circle (2pt);
%
\end{tikzpicture}%
}
%%\syntax
%% \clock{<hour>}{<minute>}{<seconds>}
\noindent\clock{1}{15}{30} \clock{2}{25}{15}
\clock{12}{58}{10} \clock{6}{10}{45}

\end{document}


# Scalable version:

\documentclass[dvipsnames]{article}
\usepackage{tikz}

\begin{document}
\newcommand\clock[4][2]{%
\begin{tikzpicture}[scale=#1,line cap=round,line width=#1*3pt]
\filldraw [fill=Goldenrod!20] (0,0) circle (2cm);
\foreach \angle / \label in
{0/3, 30/2, 60/1, 90/12, 120/11, 150/10, 180/9,
210/8, 240/7, 270/6, 300/5, 330/4}
{
\draw[line width=#1*1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node[scale=#1]{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=#1*2pt] (\angle:1.6cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red,scale=#1] at (0,.9cm) {TICK-TOCK};
\draw[rotate=90,line width=#1*2pt] (0,0) -- (-#2*30-#3*30/60:0.7cm); % hours
\draw[rotate=90,line width=#1*1.5pt] (0,0) -- (-#3*6:1cm); % minutes
\draw[rotate=90,line width=#1*.6pt,red] (0,0) -- (-#4*6:1.2cm); % seconds
\path [fill=black] (0,0) circle (3pt);
\path [fill=red] (0,0) circle (1.5pt);
%
\end{tikzpicture}%
}
%%\syntax
%% \clock[<optional scaling dim>]{<hour>}{<minute>}{<seconds>}
\noindent\clock{9}{35}{55}\clock[1.2]{1}{15}{30} \clock[.9]{2}{25}{15}
\clock[.7]{12}{58}{10} \clock[.5]{6}{10}{55}
\clock[.3]{12}{20}{22} \clock[.2]{8}{0}{5}

\end{document}


And here is a minimal animation. I don't dare to go for the inclusion of seconds hand / make the intervals small.

\documentclass[preview,border={10pt 0pt 10pt 10pt}]{standalone}

\usepackage{filecontents}
\begin{filecontents*}{clock.tex}
\documentclass[tikz,border=0pt,dvipsnames]{standalone}
\usepackage{tikz}

\begin{document}
\foreach \hdeg / \mdeg in {0/0,2/24,4/48,6/72,8/96,10/120,12/144,14/168,
16/192,18/216,20/240,22/264,24/288,26/312,28/336,30/360}{%
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=Goldenrod!30] (0,0) circle (2cm);
\foreach \angle / \label in
{0/3, 30/2, 60/1, 90/12, 120/11, 150/10, 180/9,
210/8, 240/7, 270/6, 300/5, 330/4}
{
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:1.6cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,.9cm) {TICK-TOCK};
\draw[rotate=90,line width=2pt] (0,0) -- (-\hdeg:0.7cm); % hours
\draw[rotate=90,line width=1.5pt] (0,0) -- (-\mdeg:1cm); % minutes
\path [fill=black] (0,0) circle (3pt);
\path [fill=red] (0,0) circle (2pt);
%
\end{tikzpicture}%
%}
}

\end{document}
\end{filecontents*}
%
\immediate\write18{pdflatex clock}

% convert to GIF animation
\immediate\write18{convert -delay 200 -loop 0 -density 400 -alpha remove clock.pdf clock.gif}

\usepackage{animate}
\begin{document}
See the gif file in the same folder as this file.
\end{document}


-
@SvendTveskæg It was \newcommand\clock[4][1]{% originally. Now edited by MMA :) –  Harish Kumar Sep 9 '13 at 9:49
I just broke my watch, I think I will buy one of these... :-) –  karlkoeller Sep 9 '13 at 13:21
@PSTikZ Sorry. It is a wall clock ;-). Geometrically, I was careless and file size, trust me, it could have been even larger ;-) let alone the time of compilation. I do have a almost full version, but, I hate it as it ran too long to compile. –  Harish Kumar Sep 10 '13 at 0:14
@PSTikZ: True. PSTricks is powerful than TikZ in some aspects. But you know, I am on the other side ;-) –  Harish Kumar Sep 10 '13 at 0:17

Bit off topic-answer, once I made a "mathematican clock" as a birthday present. The result was printed out, and I replaced the number plate of a real clock with it:

\documentclass[landscape,a3paper,extrafontsizes,12pt]{memoir}
\usepackage[a3paper,margin=0.2cm]{geometry}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{center}
\vspace*{\fill}

\begin{tikzpicture}
\foreach \x in {0,30,...,360} {
\draw [line width = 0.1cm] (\x:9cm) -- (\x:10.5cm);
};
\foreach \x in {0,6,...,360} {
\draw [line width = 0.05cm] (\x:10cm) -- (\x:10.5cm);
};
\draw (0:0cm) circle [radius = 0.2cm];

\node (1) at (60:7cm) {\Large $\boldsymbol{9^{9-9}}$};
\node (2) at (30:7cm) {\Large $\boldsymbol{\dfrac{9+9}{9}}$};
\node (3) at (0:7cm) {\Huge $\boldsymbol{\sqrt{\log_{9}{9^9}}}$};
\node (4) at (-30:7cm) {\Large $\boldsymbol{\sqrt{9}+\log_{9}9}$};
\node (5) at (-60:7cm) {\Large $\boldsymbol{\sqrt{9}!-\log_{9}9}$};
\node (6) at (-90:7cm) {\Huge $\boldsymbol{9 - \dfrac{9}{\sqrt{9}}}$};
\node (7) at (-120:7cm) {\Large $\boldsymbol{\sqrt{9}!+\dfrac{9}{9}}$};
\node (8) at (-150:7cm) {\Large $\boldsymbol{9 - \dfrac{9}{9}}$};
\node (9) at (-180:7cm) {\Huge $\boldsymbol{\sqrt[9]{9^9}}$};
\node (10) at (-210:7cm) {\Large $\boldsymbol{9 + \log_{9}{9}}$};
\node (11) at (-240:7cm) {\Large $\boldsymbol{\dfrac{99}{9}}$};
\node (12) at (-270:7cm) {\Huge $\boldsymbol{9 + \dfrac{9}{\sqrt{9}}}$};
\end{tikzpicture}
\vspace*{\fill}
\end{center}
\end{document}


(this is an excerpt, the original had also numbers 0-59 on each of the minutes line)

result:

There are no hands, as those were provided by the real clock

-
You should typeset the birthday present correctly; log --> \log. –  Svend Tveskæg Sep 9 '13 at 9:51
didn't knew there was a \log command. Thanks –  SztupY Sep 9 '13 at 10:25

With PSTricks.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\SpecialCoor
\begin{document}
\begin{pspicture}(-3,-3)(3,3)
\pscircle{3}
\multido{\ia=60+-30,\in=1+1}{12}{\psline(2.9;\ia)(3;\ia)\uput{2.4}[\ia](0,0){\in}}
\multido{\ia=90+90}{4}{\psline(2.8;\ia)(2.9;\ia)}
\psline[linewidth=3\pslinewidth]{<->}(2.1;90)(0,0)(1.5;0)
\end{pspicture}
\end{document}


## A clock with exhausted batteries

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\SpecialCoor
\begin{document}
\multido{\is=90+-6,\ic=0+1}{60}{%
\begin{pspicture}(-3,-3)(3,3)
\pscircle{3}
\multido{\ia=60+-30,\in=1+1}{12}{\psline(2.9;\ia)(3;\ia)\uput{2.4}[\ia](0,0){\in}}
\multido{\ia=90+90}{4}{\psline(2.8;\ia)(2.9;\ia)}
\pstVerb{/angle {\ic\space 2 mod 0 gt {90}{105} ifelse} bind def}%
\psline[linewidth=3\pslinewidth]{<->}(!2.1 angle PtoC)(0,0)(!1.5 angle 90 sub PtoC)
\psset{linecolor=red}
\psline{->}(0,0)(2.2;\is)
\pscircle*{2pt}
\end{pspicture}}
\end{document}


-
Just curious: Where is second's hand and it's Animation (your unique answer feature)? –  texenthusiast Sep 9 '13 at 7:20
Looks like \psline[linewidth=3\pslinewidth]{<->}(2.1;90)(0,0)(1.5;0) represends both hands. –  Per Alexandersson Sep 9 '13 at 7:47
Your second clock is broken. The hour hand points at 2:30, but the minute hand points at x:57. –  Jake Sep 9 '13 at 8:15
@PSTikZ: Ah, I thought you meant that the second hand is decoupled from the minutes/hours. –  Jake Sep 9 '13 at 8:23

With Metapost. This is more complicated than it has to be, because it takes care to mark off each minute, and to use different widths and lengths for five-minute ticks as opposed to one-minute ticks, but it's still pretty simple:

beginfig(1);

diameter=160;

pickup pencircle scaled 0.5;

pair r[];
for i=12 downto 1:
r[i] = r[i+1] rotatedaround (z0,30);
z[i] = r[i];
endfor
defaultfont := "cmr17";
defaultscale := 1.5;
label("12",z12);
label("6",z6);
label("9",z9);
label("3",z3);
label("1",z1);
label("5",z5);
label("7",z7);
label("11",z11 shifted (0,-1pt));
label("2",z2);
label("4",z4);
label("8",z8);
label("10",z10 shifted (1pt,0));

pair p[];
pair q[];
numeric circangle;
circangle := 0;
p[0] = z50;
for i=0 step 1 until 60:
p[i] = p[i-1] rotatedaround (z0,6);
if (i mod 5 = 0):
q[i] = 1/12[p[i],z0];
pickup pencircle scaled 2;
draw p[i]--q[i];
pickup pencircle scaled 0.5;
else:
q[i] = 1/30[p[i],z0];
pickup pencircle scaled 0.5;
draw p[i]--q[i];
fi
draw p[i-1]..p[i];
endfor

endfig;
end;


I've always been partial to Metapost, as I find it much easier to program than tikZ. tikZ does have the benefit of being able to be thrown into macros, though, as Harish Kumar's excellent answer above demonstrates.

I know that, strictly speaking, this isn't a TeX answer; but Metapost has such a pedigree among TeXnicians (even Knuth himself uses it for his figures, I'm told) that it seemed a fair answer to me.

-