GeneralAnalog Clock

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jlamber
Posts: 5
Joined: Mon Jul 27, 2009 5:32 pm

Analog Clock

Post by jlamber »

I am trying to draw the analog clock with various time to teach elementary school children how to tell time. I used tikz package and started but could finish because I don't know how to draw the number node and the hour and minute arrrows. I appreciate if someone can point me to when I am doing wrong. Thank you.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{centering}

% Define a few constants for easy configuration
\def\radius{2cm}
\def\onedegrad{1.8cm}
\def\fivedegrad{1.75cm}
\def\tendegrad{1.7cm}
\def\labelrad{1.6cm}

\begin{tikzpicture}[scale=1]
  % adding a subtle gray tone to add a bit of "personality"
  \shade[shading=radial, inner color=white, outer color=gray!15] (0,0) circle (\radius);

  \draw (0,0) circle (\radius);
  \draw[fill=black] (0,0) circle (.06mm);
  \node[draw, circle, inner sep=.2mm] (a) at (0,0) {};

  % helper lines
  %\foreach \x in {0, 30, ..., 360} \draw[very thin, gray!40] (a) -- (\x:\radius);

% main lines
  \foreach \x in {0, 6,...,360} \draw (\x:\onedegrad) -- (\x:\radius);

% labels and longer lines at...but have problem with the node
  \foreach \x in {0,30,...,330}
  {
    \node[scale=0.5] at (360-\x+90:\labelrad) {\x};
    \draw (\x:\tendegrad) -- (\x:\radius);
  };

\end{tikzpicture}
\end{centering}

\end{document}

Attachments
clock.pdf
(12.98 KiB) Downloaded 517 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Analog Clock

Post by Stefan Kottwitz »

Hi,

have a look at this modified example introducing hours and the arrows, using the calc library for a relative distance:

Code: Select all

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{centering}

% Define a few constants for easy configuration
\def\radius{2cm}
\def\onedegrad{1.8cm}
\def\fivedegrad{1.75cm}
\def\tendegrad{1.7cm}
\def\labelrad{1.6cm}

\begin{tikzpicture}[scale=1]
  % adding a subtle gray tone to add a bit of "personality"
  \shade[shading=radial, inner color=white, outer color=gray!15] (0,0) circle (\radius);

  \draw (0,0) circle (\radius);
  \draw[fill=black] (0,0) circle (.06mm);
  \node[draw, circle, inner sep=.2mm] (a) at (0,0) {};

  % helper lines
  %\foreach \x in {0, 30, ..., 360} \draw[very thin, gray!40] (a) -- (\x:\radius);

% main lines
  \foreach \x in {0, 6,...,360} \draw (\x:\onedegrad) -- (\x:\radius);

% labels and longer lines at...but have problem with the node
  \foreach \x in {1,...,12}
  {
    \node[scale=0.5] (\x) at (360-30*\x+90:\labelrad) {\x};
    \draw (30*\x:\tendegrad) -- (30*\x:\radius);
  };
  \draw[very thick,->] (0,0) -- ($(0,0)!0.7!(3)$);
  \draw[thick,->] (0,0) -- (12);

\end{tikzpicture}
\end{centering}

\end{document}
Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Analog Clock

Post by localghost »

pgf/tikZ manual (p. 391/392).


Best regards
Thorsten
jlamber
Posts: 5
Joined: Mon Jul 27, 2009 5:32 pm

Re: Analog Clock

Post by jlamber »

This works great...thank you for your help.
Post Reply