答案1
当然,但是没有节点会更容易:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (0.5,0.5) circle[radius=0.5];
\foreach \i/\c in {0/100,1/80,2/60,3/40,4/20,5/10} {
\fill[black!\c] ({1-1/pow(2,\i)},0) rectangle (1,1);
}
\end{scope}
\begin{scope}[yshift=-1.5cm]
\clip (0.5,0.5) circle[radius=0.5];
\foreach \i/\c in {0/red,1/blue,2/green,3/yellow,4/magenta,5/brown} {
\fill[\c] ({1-1/pow(2,\i)},0) rectangle (1,1);
}
\end{scope}
\end{tikzpicture}
\end{document}
如果您仍然希望用这种模式填充节点,则可以使用path picture
s:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
gray steps/.style={
path picture={
\foreach \i/\c in {0/100,1/80,2/60,3/40,4/20,5/10} {
\fill[black!\c]
let \p1=($(path picture bounding box.east)-(path picture bounding box.west)$) in
([xshift={(1-1/pow(2,\i))*\x1}]path picture bounding box.south west)
rectangle
(path picture bounding box.north east);
}
}
},
colorful steps/.style={
path picture={
\foreach \i/\c in {0/red,1/blue,2/green,3/yellow,4/magenta,5/brown} {
\fill[\c]
let \p1=($(path picture bounding box.east)-(path picture bounding box.west)$) in
([xshift={(1-1/pow(2,\i))*\x1}]path picture bounding box.south west)
rectangle
(path picture bounding box.north east);
}
}
}
}
\begin{document}
\begin{tikzpicture}
\node[gray steps, circle, text width=1cm] at (0,0) {};
\node[colorful steps, circle, text width=1cm] at (0,-1.5) {};
\node[colorful steps, text width=1cm] at (0,-2.5) {};
\end{tikzpicture}
\end{document}
如果您需要多个节点,并且除了颜色及其数量之外,模式始终相同,则可以将上述内容概括为:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
colorful steps/.style={
path picture={
\foreach \c [count=\i from 0] in {#1} {
\fill[\c]
let \p1=($(path picture bounding box.east)-(path picture bounding box.west)$) in
([xshift={(1-1/pow(2,\i))*\x1}]path picture bounding box.south west)
rectangle
(path picture bounding box.north east);
}
}
}
}
\begin{document}
\begin{tikzpicture}
\node[colorful steps={red,blue}, circle, text width=1cm] at (0,0) {};
\node[colorful steps={red,blue,green,yellow,magenta,brown}, circle, text width=1cm] at (0,-1.5) {};
\node[colorful steps={black, black!80, black!60}, circle, text width=1cm] at (0,-3) {};
\end{tikzpicture}
\end{document}