Generate analog clock with numbered face

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}

enter image description here

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}

enter image description here

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}

enter image description here


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]
\filldraw [fill=cyan] (0,0) circle [radius=2cm];
\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}

enter image description here

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}}{%
\def\radius{#1}%
\begin{tikzpicture}[line cap=rect,line width=0.055*\radius]
\filldraw [fill=#3] (0,0) circle [radius=\radius];
\foreach \angle [count=\xi] in {60,30,...,-270}
{
  \draw[line width=1pt] (\angle:0.9*\radius) -- (\angle:\radius);
  \node[font=#2] at (\angle:0.68*\radius) {\textsf{\xi}};
}
\foreach \angle in {0,90,180,270}
  \draw[line width=0.04*\radius] (\angle:0.82*\radius) -- (\angle:\radius);
\draw (0,0) -- (120:0.4*\radius);
\draw (0,0) -- (90:0.5*\radius);
\end{tikzpicture}%
}

\begin{document}

\Clock\quad\Clock[1cm][\footnotesize][orange]

\end{document}

enter image description here


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:

LaTeX results

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

Tags:

Symbols