![编辑(特别针对瑟斯顿)](https://linux22.com/image/345878/%E7%BC%96%E8%BE%91%EF%BC%88%E7%89%B9%E5%88%AB%E9%92%88%E5%AF%B9%E7%91%9F%E6%96%AF%E9%A1%BF%EF%BC%89.png)
我正在尝试绘制一个类似http://www.ebay.com.au/itm/KUMON-Study-Wall-Clock-Learning-how-to-tell-time-easily-/252645374477学习如何在整页图表上使用 tikz
我可以画出时钟的外部和标签,但是我不知道如何在样板时钟中用粉色和黄色绘制和着色内部小时数。
我如何创建 12 个内部小时节点,以便每个小时都变成黄色和粉色?
我已经完成了以下尝试绘制内部时间的代码。但我不确定如何完成它,以便我可以单独为每个节点着色
\documentclass{article}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\newcommand\clock{%
\begin{tikzpicture}[overlay,remember picture, 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
%
\foreach \angle [count=\label] 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 (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}%
}
\clock
\end{document}
任何建议都会很有帮助,因为我不确定如何做到这一点?
谢谢
答案1
只是为了好玩,这里有一个使用contour
包的解决方案......
\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}
编辑(特别针对瑟斯顿)
要添加猫和老鼠,请添加以下几行...
...在序言中:
\usepackage{marvosym}
\usepackage{tikzsymbols}
... 在最后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};
答案2
你可以画一个粗圆圈
\draw[line width=1.5cm, red!30] (0,0) circle (7.00cm);
随后填充一些区域:
\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;
完整代码:
\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}
答案3
另一种方法是测试是\label
偶数还是奇数,并相应地进行填充:
\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
}
该代码还绘制了小时标签,避免了\foreach
您使用额外的标签。
这是一个改进的 MWE,它使用最外圈作为刻度的参考,因此如果您改变它的尺寸,几乎整个绘图都会适应(只有彩色圆圈不会)。
\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}