Draw Clock to help learn time
Just for fun, here is a solution using contour
package...
\documentclass[tikz]{standalone}
\usepackage{lmodern}
\usepackage[outline]{contour}
\newcommand\clock[2]{%
\begin{tikzpicture}[cap=round,rotate=90]
% colors
\colorlet{minutes color}{blue!50!cyan!70!black}
\colorlet{bg hours 0}{yellow}
\colorlet{bg hours 1}{red!50}
\colorlet{hours color}{red!80!black}
% styles
\tikzset{
minutes/.style={circle,inner sep=0,text width=5mm,align=center,font=\bfseries},
minutes 0/.style={fill=minutes color,text=white,minutes},
minutes 1/.style={text=minutes color,fill=white,minutes},
minutes font/.style={font=\normalsize},
hours/.style={font=\fontsize{60}{66}\selectfont\bfseries,text=hours color,align=center},
mini hours font/.style={font=\fontsize{40}{46}\selectfont\bfseries},
}
% radii
\def\bigradius{80mm}
\def\minuteradius{75mm}
\def\hourradius{60mm}
\def\minihourminradius{25mm}
\def\minihourmaxradius{45mm}
\pgfmathsetmacro\minihourradius{(\minihourmaxradius + \minihourminradius)*.5}
\def\hourwidth{2mm}
\def\minutewidth{1mm}
% big circle
\filldraw [fill=white,draw=minutes color] (0,0) circle (\bigradius);
% minutes marks
\foreach \angle[count=\c from 0,evaluate={\c as \hourmark using notequal(int(mod(\c,5)),0)}]
in {0,6,...,354}{ \path (-\angle:\minuteradius) node[minutes \hourmark]{\c}; }
% hours marks
\foreach \angle[count=\c from 1,evaluate={\c as \col using int(mod(\c,2))}] in {30,60,...,360}{
\path (-\angle:\hourradius) node[hours]{\c};
\path[fill=bg hours \col]
(-\angle:\minihourminradius) -- (-\angle:\minihourmaxradius)
arc(-\angle:-\angle-30:\minihourmaxradius) -- (-\angle-30:\minihourminradius)
arc(-\angle-30:-\angle:\minihourminradius) -- cycle;
\path (-\angle-15:\minihourradius pt) node[mini hours font]{\textcolor{white}{\contour{hours color}{\c}}};
}
% hands
\pgfmathsetmacro\hourangle{-#1*30-#2*.5}
\pgfmathsetmacro\minuteangle{-#2*6}
\fill[rotate=\hourangle,fill=hours color] ++(0,\hourwidth) arc(90:270:\hourwidth) -- ++(50mm,0)
-- ++(\hourwidth,\hourwidth) -- ++(-\hourwidth,\hourwidth) -- ++(-50mm,0) -- cycle ;
\fill[rotate=\minuteangle,fill=minutes color] ++(0,\minutewidth) arc(90:270:\minutewidth) -- ++(70mm,0)
-- ++(\minutewidth,\minutewidth) -- ++(-\minutewidth,\minutewidth) -- ++(-70mm,0) -- cycle ;
\end{tikzpicture}%
}
\begin{document}
\clock{19}{45}
\end{document}
Edit (specially for Thruston)
To add the cat and the mouse, add the following lines...
... in the preamble:
\usepackage{marvosym}
\usepackage{tikzsymbols}
... at the end of the tikzpicture
:
\path (0:15mm) node[fill=cyan,circle,inner sep=0]{\Cat[3]};
\path (180:15mm) node[fill=lime,circle,inner sep=0,font=\fontsize{45}{50}\selectfont]{\ComputerMouse};
You can draw a thick circle
\draw[line width=1.5cm, red!30] (0,0) circle (7.00cm);
and later on fill some sectors:
\foreach \i in {60,0,...,-240}
\fill[yellow!30] (\i:6.25cm) -- (\i:7.75cm) arc (\i:\i-30:7.75cm)--(\i-30:6.25cm) arc (\i-30:\i:6.25cm)--cycle;
Complete code:
\documentclass{standalone}
\usepackage{tikz}
\newcommand\clock{%
}
\begin{document}
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=white] (0,0) circle (10cm);
\foreach \angle [count=\label] in {60,30,...,-270} %Draw 10 minute ticks
{
\draw[line width=1pt] (\angle:9.5cm) -- (\angle:10cm);
\draw (\angle:9cm) node{\label};
}
%
% Replace the following bit to draw inners hours in node
%
\draw[line width=1.5cm, red!30] (0,0) circle (7.00cm);
\foreach \angle [count=\label, remember=\angle as \last (initially -270)] in {60,30,...,-270} %Try to draw inner hours
{
\draw[line width=1pt] (\angle:6.25cm) -- (\angle:7.75cm); %Draws part of inner hour
%\draw[line width=1.5cm] (\last:6.25cm) arc(\last:\angle:6.25cm); %Draws part of inner hour
}
\foreach \i in {60,0,...,-240}
\fill[yellow!30] (\i:6.25cm) -- (\i:7.75cm) arc (\i:\i-30:7.75cm)--(\i-30:6.25cm) arc (\i-30:\i:6.25cm)--cycle;
\draw (0,0) circle (6.25cm);
\draw (0,0) circle (7.75cm);
\foreach \angle [count=\label] in {45,15,...,-285} %Draw inner hour
{
\draw (\angle:7.cm) node{\label};
}
%
% Replace the proceeding bit
%
\foreach \angle [count=\label] in {84,78,...,-270} % Draw Second Ticks
{
\draw[line width=1pt] (\angle:9.75cm) -- (\angle:10cm);
\draw (\angle:9.5cm) node{\label};
}
\foreach \angle in {0,90,180,270}
\draw[line width=4pt] (\angle:9cm) -- (\angle:10cm);
\path [fill=red] (0,0) circle (2pt);
%
\end{tikzpicture}%
\end{document}
One other way is to test if \label
is even or odd and do the filling accordingly:
\foreach \angle [count=\label] in {60,30,...,-270} %Try to draw inner hours
{
\pgfmathparse{isodd(\label)}
\ifnum\pgfmathresult=1%
\draw[yellow, line width=1.5cm, line cap=butt] (\angle:7cm) arc[radius=7cm, start angle=\angle, delta angle=-30] node[midway, black]{\label};
\else%
\draw[pink, line width=1.5cm, line cap=butt] (\angle:7cm) arc[radius=7cm, start angle=\angle, delta angle=-30] node[midway, black]{\label};
\fi
}
That code also draws the hour labels, avoinding one extra \foreach
you were using.
Here's an improved MWE, that uses the most outer circle as reference for the ticks, so if you chagen ist size almost the whole drawing adapts (only the colored circle doesn't.
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[%overlay, remember picture,
line cap=round, line width=3pt]
\node[circle, draw, minimum size=20cm, outer sep=-2pt] (Clock) {};
\foreach \angle [count=\label] in {60,30,...,-270}{%Draw 10 minute ticks
\draw[line width=1pt] (Clock.\angle) -- ++(\angle:-.5cm) node[shift={(\angle:-2em)}]{\label};
}
% Replace the following bit to draw inners hours in node
\foreach \angle [count=\label] in {60,30,...,-270}{%Try to draw inner hours
\pgfmathparse{isodd(\label)}
\ifnum\pgfmathresult=0%
\draw[double=yellow!30, double distance=1.5cm, line cap=butt] (\angle:7cm) arc[radius=7cm, start angle=\angle, delta angle=-30] node[midway, black]{\label};
\else%
\draw[double=pink, double distance=1.5cm, line cap=butt] (\angle:7cm) arc[radius=7cm, start angle=\angle, delta angle=-30] node[midway, black]{\label};
\fi
}
% Replace the proceeding bit
\foreach \angle [count=\label] in {84,78,...,-270}{% Draw Second Ticks
\draw[line width=1pt] (Clock.\angle) -- ++(\angle:-.25cm) node[shift={(\angle:-1em)}]{\label};
}
\foreach \angle in {0,90,180,270} \draw[line width=4pt] (Clock.\angle) -- ++(\angle:-1cm);
\fill[red] circle (2pt);
%
\end{tikzpicture}%
\end{document}