Share

PGF and TikZ -- Graphic systems for TeX

Subscribe

How Draw Analog Clock

  1. 2009-10-16 14:30:55 UTC

    I am trying to draw an analog clock to teach elementary students how to tell time. Unfortunately I am not able to complete it because I don't know how to layout the node from 1-12. Also, how do you draw the arrow at various time?

    \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 every 6 degrees
      \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}
    

    Thank you, John

  2. 2009-10-17 14:33:30 UTC

    Hi John You can do it by extending your already made foreach statement. I have also added a command which lets you easily drawn the time. You can then yourself extend with coloring the lines! :D

    \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}
      \def\longline{1.6cm}
      \def\shortline{.6cm}
      \def\drawtime(#1:#2){
          \pgfmathparse{90-#1 *30-#2 *.5}
          \edef\tmpA{\pgfmathresult}
          \draw (0,0) -- (\tmpA:\shortline);
          \pgfmathparse{90-#2 *6}
          \edef\tmpA{\pgfmathresult}
          \draw (0,0) -- (\tmpA:\longline);
      }
      \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 every 6 degrees
        \foreach \x/\clock in       {30/1,60/2,90/3,120/4,150/5,180/6,210/7,240/8,270/9,300/10,330/11,360/12} {
            \node[scale=0.5] at (360-\x+90:\labelrad) {\clock};
            \draw (\x:\tendegrad) -- (\x:\radius);
        }
        % Here is the time drawn
        \drawtime (4:33)
      \end{tikzpicture}
      \end{centering}
    
      \end{document}
    

    Hope this helps!

    Kind regards Nick

< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.