我在帖子里看到了“抽轮盘代码”:
现在我想改变一些事情:
每个段有 8 种不同的颜色和渐变填充。
在每个段中插入 3 个图标。
在轮子的中心插入一张图片。
这是更改后的代码
% arara: pdflatex: {synctex: yes, action: nonstopmode}
% By J. Leon V. Share as Beerware philosophy
\documentclass[border=20pt]{standalone}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{pgfmath}
\usepackage{xifthen}
\usetikzlibrary{decorations.text, arrows.meta,calc,shadows.blur,shadings}
\renewcommand*\familydefault{\sfdefault} % Set font to serif family
\begin{document}
\begin{tikzpicture}[
% Environment Cfg
font=\Large,
scale=1,
% Styles
Grid/.style={
loosely dotted,
line width=1.5pt,
color=black
},
Separator/.style={
thick,
color=black!50
},
Border/.style={
line width=1pt,
color=red!60
},
Border2/.style={
line width=2pt,
color=red!60
},
Fill/.style={
fill=black,
opacity=0.1
}
]
% lifeweel from many codes arround TEX.SE
%Variables: 1:levels, 2:grid 3:number of features 4: Feature_name/quantity
% 5: anchor aling 6: numbers position 7:Relative position 8:ID
\def\lifeweel#1#2#3#4[#5][#6](#7)(#8){%
\begin{scope}[shift={(#7)}]
%Decoration
\foreach \n in {0,#2,...,#1}{
\draw[fill=black, opacity=0.1] (0,0) circle [radius=\n];}
%Drawing the grid and numbers.
\foreach \n in {0,#2,...,#1}{
\draw[Grid] (0,0) circle [radius=\n];
\node[anchor=#5] (A) at (#6:\n+0.2){\n};}
%Drawing features separations.
\foreach \m [count=\i] in {0,1,...,#3}{
\draw[Separator] (0,0) -- (360/#3*\i: #1);}
%Drawing the border
\draw[Border] (0,0) circle [radius=#1];
%Drawing the names
\foreach \o/\p [count=\j] in {#4}{
\pgfmathparse{int(360/#3*\j)}
\ifthenelse{ \pgfmathresult >180}
{% True
\path[%Reverse
decoration={
raise = -0.8ex,
text along path,
text = {|\huge|\o},
text align = center,
reverse path
},
decorate
]
(360/#3*\j:#1+0.7) arc (360/#3*\j:360/#3*(\j-1):#1+0.7);%\path
}
{%False
\path[%Normal
decoration={
raise = -0.8ex,
text along path,
text = {|\huge|\o},
text align = center
},
decorate
]
(360/#3*\j:#1+0.7) arc (360/#3*\j:360/#3*(\j-1):#1+0.7); %Path
}
\draw[Border2]
(360/#3*\j:\p) coordinate (#8a\j)
arc (360/#3*\j:360/#3*(\j-1):\p) coordinate (#8b\j);
\draw[fill=red, opacity=0.2]
(0,0) -- (360/#3*\j:\p) arc (360/#3*\j:360/#3*(\j-1):\p);
}
\pgfmathparse{int(#3+1)} % Principle of uroboro
\coordinate (#8b\pgfmathresult) at (#8b1);
\foreach \o/\p [count=\i, evaluate=\i as \x using int(\i+1)] in {#4}{%Close the perimete
\draw[Border2] (#8a\i) -- (#8b\x);}
\end{scope}
}
%Variables: 1:levels, 2:grid 3:number of features 4: Feature_name/quantity
% 5: anchor aling 6: numbers position 7:Relative position 8: ID
\def\lifeweelS#1#2#3#4[#5][#6](#7)(#8){%
\begin{scope}[shift={(#7)}]
%Drawing the numbers.
\foreach \n [count=\m] in {0,#2,...,#1}{
\node[anchor=#5] (A) at (#6:\n+0.2){\n};
}
%Drawing the grid
\foreach \n in {0,#2,...,#1}{
\foreach [count=\i, evaluate=\i as \x using int(\i+1)]\m in {0,1,...,#3}{
\draw[Grid](360/#3*\i:\n) -- (360/#3*\x:\n);
\draw[Fill](360/#3*\i:\n) -- (0,0) -- (360/#3*\x:\n);
}
}
%Drawing features separations.
\foreach \m [count=\i] in {0,1,...,#3}{
\draw[Separator] (0,0) -- (360/#3*\i: #1);}
%Drawing the border
\draw[fill=black, opacity=0.1] (0,0) circle [radius=#1];
\draw[Border] (0,0) circle [radius=#1];
%Drawing the names
\foreach \o/\p [count=\j from 0] in {#4}{
\pgfmathparse{int(360/#3*\j)}
\ifthenelse{\pgfmathresult =90 \OR \pgfmathresult =270}
{%True
\draw (360/#3*\j:#1+0.7) node [anchor=center]{\huge\o};
}
{%false
\ifthenelse{\pgfmathresult <90 \OR \pgfmathresult >270}
{% True
\draw (360/#3*\j:#1+0.7) node [anchor=west]{\huge\o};
}
{%False
\draw (360/#3*\j:#1+0.7) node [anchor=east]{\huge\o};
}
}
\coordinate (#8c\j) at (360/#3*\j:\p);
}
\coordinate (#8c#3) at (#8c0);
\foreach \o/\p [count=\i from 0, evaluate=\i as \x using int(\i+1)] in {#4}{%Close the perimete
\draw[Border2] (#8c\i) -- (#8c\x);
\draw[fill=red, opacity=.2] (#8c\i) --(0,0) -- (#8c\x);
}
\end{scope}
}
% This function draws the lifeweel
%\lifeweel{levels}{grid}{number of features}{feature_name/quantity}[anchor angle][numbers direction in degrees][relative position](ID);
\lifeweel{10}{10}{8}{
Money/10,
Entertainment/10,
Romance/10,
Presonal Growth/10,
Friends {\&} Family/10,
Financial/10,
Spiritual/10,
Health/10
}[45][180](0,0)(1);
\end{tikzpicture}
\end{document}
答案1
不同的背景颜色和渐变填充都来自于此回答。
中心图像来自我最近回答,使用pullquote
环境。
完整代码如下:
\documentclass[border=20pt]{standalone}
\usepackage{xcolor}
\usepackage{tikz,pgf,xparse}
\usepackage{pgfmath}
\usepackage{xifthen}
\usetikzlibrary{decorations.text, arrows.meta,calc,shadows.blur,shadings}
\renewcommand*\familydefault{\sfdefault} % Set font to serif family
%%%%%%%%%%%%%%%%% FOR COLOR TRANSITION %%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\vardonut}[1]{
\newcounter{num}
\foreach \content/\size/\colour in {#1}
\stepcounter{num};
\foreach \content/\size/\colour [count=\i] in {#1}{
\draw[white,very thick,top color=\colour!50!black, bottom color=\colour, shading angle={-90+360/\thenum/2+(\i-1)*360/\thenum}]
({2*cos((\i-1)*360/\thenum)},{2*sin((\i-1)*360/\thenum)}) arc[radius = 2, start angle={(\i-1)*360/\thenum}, delta angle=360/\thenum] --
({(2+\size)*cos(\i*360/\thenum)},{(2+\size)*sin(\i*360/\thenum)}) arc[radius = {2+\size}, start angle={\i*360/\thenum}, delta angle=-360/\thenum] --
cycle;
% \node[white,font=\large] at ({(\i-1)*360/\thenum+360/\thenum/2}:{\size/2+2}) {\content};
}
}
%%%%%%%%%%%%%%%%%%%%%END OF COLOR TRANSITION %%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[
% Environment Cfg
font=\Large,
scale=1,
% Styles
Grid/.style={
loosely dotted,
line width=1.5pt,
color=black
},
Separator/.style={
thick,
color=black!50
},
Border/.style={
line width=1pt,
color=red!60
},
Border2/.style={
line width=2pt,
color=red!60
},
Fill/.style={
fill=black,
opacity=0.1
}
]
% lifeweel from many codes arround TEX.SE
%Variables: 1:levels, 2:grid 3:number of features 4: Feature_name/quantity
% 5: anchor aling 6: numbers position 7:Relative position 8:ID
\def\lifeweel#1#2#3#4[#5][#6](#7)(#8){%
\begin{scope}[shift={(#7)}]
%Decoration
\foreach \n in {0,#2,...,#1}{
\draw[fill=black, opacity=0.1] (0,0) circle [radius=\n];}
%Drawing the grid and numbers.
\foreach \n in {0,#2,...,#1}{
\draw[Grid] (0,0) circle [radius=\n];
\node[anchor=#5] (A) at (#6:\n+0.2){\n};}
%Drawing features separations.
\foreach \m [count=\i] in {0,1,...,#3}{
\draw[Separator] (0,0) -- (360/#3*\i: #1);}
%Drawing the border
\draw[Border] (0,0) circle [radius=#1];
%Drawing the names
\foreach \o/\p [count=\j] in {#4}{
\pgfmathparse{int(360/#3*\j)}
\ifthenelse{ \pgfmathresult >180}
{% True
\path[%Reverse
decoration={
raise = -0.8ex,
text along path,
text = {|\huge|\o},
text align = center,
reverse path
},
decorate
]
(360/#3*\j:#1+0.7) arc (360/#3*\j:360/#3*(\j-1):#1+0.7);%\path
}
{%False
\path[%Normal
decoration={
raise = -0.8ex,
text along path,
text = {|\huge|\o},
text align = center
},
decorate
]
(360/#3*\j:#1+0.7) arc (360/#3*\j:360/#3*(\j-1):#1+0.7); %Path
}
\draw[Border2]
(360/#3*\j:\p) coordinate (#8a\j)
arc (360/#3*\j:360/#3*(\j-1):\p) coordinate (#8b\j);
\draw[fill=red, opacity=0.2]
(0,0) -- (360/#3*\j:\p) arc (360/#3*\j:360/#3*(\j-1):\p);
}
\pgfmathparse{int(#3+1)} % Principle of uroboro
\coordinate (#8b\pgfmathresult) at (#8b1);
\foreach \o/\p [count=\i, evaluate=\i as \x using int(\i+1)] in {#4}{%Close the perimete
\draw[Border2] (#8a\i) -- (#8b\x);}
\end{scope}
}
%Variables: 1:levels, 2:grid 3:number of features 4: Feature_name/quantity
% 5: anchor aling 6: numbers position 7:Relative position 8: ID
\def\lifeweelS#1#2#3#4[#5][#6](#7)(#8){%
\begin{scope}[shift={(#7)}]
%Drawing the numbers.
\foreach \n [count=\m] in {0,#2,...,#1}{
\node[anchor=#5] (A) at (#6:\n+0.2){\n};
}
%Drawing the grid
\foreach \n in {0,#2,...,#1}{
\foreach [count=\i, evaluate=\i as \x using int(\i+1)]\m in {0,1,...,#3}{
\draw[Grid](360/#3*\i:\n) -- (360/#3*\x:\n);
\draw[Fill](360/#3*\i:\n) -- (0,0) -- (360/#3*\x:\n);
}
}
%Drawing features separations.
\foreach \m [count=\i] in {0,1,...,#3}{
\draw[Separator] (0,0) -- (360/#3*\i: #1);}
%Drawing the border
\draw[fill=black, opacity=0.1] (0,0) circle [radius=#1];
\draw[Border] (0,0) circle [radius=#1];
%Drawing the names
\foreach \o/\p [count=\j from 0] in {#4}{
\pgfmathparse{int(360/#3*\j)}
\ifthenelse{\pgfmathresult =90 \OR \pgfmathresult =270}
{%True
\draw (360/#3*\j:#1+0.7) node [anchor=center]{\huge\o};
}
{%false
\ifthenelse{\pgfmathresult <90 \OR \pgfmathresult >270}
{% True
\draw (360/#3*\j:#1+0.7) node [anchor=west]{\huge\o};
}
{%False
\draw (360/#3*\j:#1+0.7) node [anchor=east]{\huge\o};
}
}
\coordinate (#8c\j) at (360/#3*\j:\p);
}
\coordinate (#8c#3) at (#8c0);
\foreach \o/\p [count=\i from 0, evaluate=\i as \x using int(\i+1)] in {#4}{%Close the perimete
\draw[Border2] (#8c\i) -- (#8c\x);
\draw[fill=red, opacity=.2] (#8c\i) --(0,0) -- (#8c\x);
}
\end{scope}
}
% This function draws the lifeweel
%\lifeweel{levels}{grid}{number of features}{feature_name/quantity}[anchor angle][numbers direction in degrees][relative position](ID);
\lifeweel{10}{10}{8}{
Money/10,
Entertainment/10,
Romance/10,
Presonal Growth/10,
Friends {\&} Family/10,
Financial/10,
Spiritual/10,
Health/10
}[45][180](0,0)(1);
\ColourTransitionCircle[inner=0,outer=8,angle=40]{red,yellow,blue,blue,green}
\draw (0,0)circle (8);
\tikzset{
d1/.pic={
\foreach \t in {10,55,100,145,190,235,280,325} {
\draw[fill, red,thick] (\t:9) circle (0.5cm);
}
}
}
\tikzset{
d2/.pic={
\foreach \t in {22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5} {
\draw[fill, blue,thick] (\t:9) circle (0.5cm);
}
}
}
\tikzset{
d3/.pic={
\foreach \t in {35,80,125,170,215,260,305,350} {
\draw[fill,orange,thick] (\t:9) circle (0.5cm);
}
}
}
\tikzset{
d4/.pic={\node[circle,draw,minimum size=5cm,
text=white,
path picture={
\node at (path picture bounding box.center){
\includegraphics[scale=1]{example-image-a}
};
}]{};}
}
\pic at (0,0) {d1};
\pic at (0,0) {d2};
\pic at (0,0) {d3};
\pic at (0,0) {d4};
\end{tikzpicture}
\end{document}
输出为:
答案2
只是为了好玩。尝试“重新发明轮子”。这个练习的目的不是回答问题,即我认为勾选应该放在Ferahfeza 的精彩回答. 目的是
- 消除冗余。例如,特征的数量已经由特征列表的条目数量决定。
- 让事情变得更加 Ti钾Zy。与其定义一个带有 8 个参数的命令,不如只关注相关数据,并将所有参数存储在 pgf 键中。这样做还有一个好处,如果其他人要自定义它,那么类似于的内容可能比更容易
\pgfkeysvalueof{/tikz/life wheel/radius}
解释#1
。而且很容易添加更多可能性,而无需更改命令的语法。 - 删除不必要的包。没有必要加载
xifthen
,Ti钾Z 允许使用内置功能区分所有情况。(并且\usepackage{pgfmath}
不必加载。)
这个答案将命令归结为
\LifeWeel[radius=9,outer image radius=0.8,%
colors={"red","blue","magenta","purple","orange","green"}
]{"example-image-duck","example-image-a","example-image-b","example-image-c"}{%
Money/10,
Entertainment/10,
Romance/10,
Personal Growth/10,
Friends {\&} Family/10,
Financial/10,
Spiritual/10,
Health/10}
其中第一个参数是要包含的图形列表(第一个是中间的图形),第二个参数是功能列表。其他所有内容都可以通过作为第零个参数传递的选项来控制。
\documentclass[border=20pt]{standalone}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.text,shadings}
\renewcommand*\familydefault{\sfdefault} % Set font to serif family
% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
\stepcounter{smuggle}%
\expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
\aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
\smuggleone{#2}%
\ifnum#1>1
\aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
\fi
}
\begin{document}
\begin{tikzpicture}[
% Environment Cfg
font=\Large,
scale=1,
% Styles
]
\tikzset{life wheel/.cd,
radius/.initial=10,
outer image radius/.initial=1,
inner image radius/.initial=2,
outer image parameters/.initial={width=2.5cm},
inner image parameters/.initial={width=5cm},
Separator/.style={thick, color=black!50},
Border/.style={line width=1pt,color=red!60,shading=color wheel},
colors/.initial={}
}
% lifeweel from many codes arround TEX.SE
%Variables: 1:images, 2:image 3:number of features 4: Feature_name/quantity
% 5: anchor aling 6: numbers position 7:Relative position 8:ID
\newcommand\LifeWeel[3][]{%
\def\imglst{{#2}}
\tikzset{life wheel/.cd,#1}
\edef\LstColors{\pgfkeysvalueof{/tikz/life wheel/colors}}
\edef\NumColors{0}
\foreach \X [count=\Y starting from 1] in \LstColors
{\edef\NumColors{\Y}
\smuggle[2]{\NumColors}}
\foreach \X [count=\Y starting from 0] in {#2}
{\edef\NumImages{\Y}
\smuggle[2]{\NumImages}}
\foreach \X [count=\Y] in {#3}
{\edef\NumFeatures{\Y}
\smuggle[2]{\NumFeatures}}
%Drawing the border
\draw[life wheel/Border] (0,0) circle [radius=\pgfkeysvalueof{/tikz/life wheel/radius}];
%Drawing features separations.
\ifnum\NumColors>1
\foreach \m [count=\i] in {1,...,\NumFeatures}{
\pgfmathtruncatemacro{\myi}{mod(\i-1,\NumColors)}
\pgfmathsetmacro{\mycolor}{{\LstColors}[\myi]}
\draw[life wheel/Separator,top color=\mycolor!75!black,
bottom color=\mycolor,shading angle={-90+(360/\NumFeatures)*(\i-0.5)}] (0,0) -- (360/\NumFeatures*\i:\pgfkeysvalueof{/tikz/life wheel/radius})
arc({(360/\NumFeatures)*\i}:{(360/\NumFeatures)*(\i-1)}:\pgfkeysvalueof{/tikz/life wheel/radius})
-- cycle;}
\else
\foreach \m [count=\i] in {0,1,...,\NumFeatures}{
\draw[life wheel/Separator] (0,0) -- (360/\NumFeatures*\i:\pgfkeysvalueof{/tikz/life wheel/radius});}
\fi
%Drawing the names
\foreach \o/\p [count=\j] in {#3}{
\pgfmathtruncatemacro{\myint}{ifthenelse(sin(360/\NumFeatures*\j)<0,-1,1)}
\ifnum\myint<0% True
\path[%Reverse
decoration={
raise = -0.8ex,
text along path,
text = {|\huge|\o},
text align = center,
reverse path
},
decorate
]
(360/\NumFeatures*\j:\pgfkeysvalueof{/tikz/life wheel/radius}+0.7) arc (360/\NumFeatures*\j:360/\NumFeatures*(\j-1):\pgfkeysvalueof{/tikz/life wheel/radius}+0.7);%\path
\else%False
\path[%Normal
decoration={
raise = -0.8ex,
text along path,
text = {|\huge|\o},
text align = center
},
decorate
]
(360/\NumFeatures*\j:\pgfkeysvalueof{/tikz/life wheel/radius}+0.7) arc (360/\NumFeatures*\j:360/\NumFeatures*(\j-1):\pgfkeysvalueof{/tikz/life wheel/radius}+0.7); %Path
\fi
\foreach \X in {1,...,\NumImages}
{\pgfmathsetmacro{\tmp}{360/\NumFeatures*\j+((1-2*\X)/(2*\NumImages))*360/\NumFeatures}
\pgfmathsetmacro{\imgname}{\imglst[\X]}
\begin{scope}
\clip (\tmp:{\pgfkeysvalueof{/tikz/life
wheel/radius}-1.1*\pgfkeysvalueof{/tikz/life wheel/outer image radius}})
circle[radius=\pgfkeysvalueof{/tikz/life wheel/outer image radius}];
\node[rotate={\tmp-\myint*90}] at
(\tmp:{\pgfkeysvalueof{/tikz/life wheel/radius}-1.1*\pgfkeysvalueof{/tikz/life wheel/outer image radius}})
{\edef\temp{\noexpand\includegraphics[\pgfkeysvalueof{/tikz/life wheel/outer image parameters}]{\imgname}}
\temp};
\end{scope}
}
}
\begin{scope}
\pgfmathsetmacro{\imgname}{\imglst[0]}
\clip (0,0) circle[radius=\pgfkeysvalueof{/tikz/life wheel/inner image radius}];
\node at (0,0)
{\edef\temp{\noexpand\includegraphics[\pgfkeysvalueof{/tikz/life wheel/inner image parameters}]{\imgname}}
\temp};
\end{scope}
}
% This function draws the lifeweel
%\LifeWeel{figures}{list of features in the form feature_name/quantity}
\LifeWeel[radius=9,outer image radius=0.8,%
colors={"red","blue","magenta","purple","orange","green"}
]{"example-image-duck","example-image-a","example-image-b","example-image-c"}{%
Money/10,
Entertainment/10,
Romance/10,
Personal Growth/10,
Friends {\&} Family/10,
Financial/10,
Spiritual/10,
Health/10}
\end{tikzpicture}
\end{document}
如果你省略颜色列表,即
\LifeWeel[radius=9,outer image radius=0.8,%
%colors={"red","blue","magenta","purple","orange","green"}
]{"example-image-duck","example-image-a","example-image-b","example-image-c"}{%
Money/10,
Entertainment/10,
Romance/10,
Personal Growth/10,
Friends {\&} Family/10,
Financial/10,
Spiritual/10,
Health/10}
我原本以为这个问题是关于