几年前我为我的学生画了一个彩色轮子。我很满意。
但是代码很丑陋,因为我没有使用 \foreach 命令,所以它很大而且很乱......例如:
\path[postaction={decoration={
text along path,
text={ jaune-vert},
text align=center,
reverse path
},
decorate}] (45:4.6) arc (45:75:4.6);
对于每种颜色...这不是最有效的方法!
这是我的新代码(更优雅的解决方案),仅适用于颜色名称
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows,decorations.text}
\begin{document}
\begin{tikzpicture}
\edef\ang{0}
\foreach \x/\text in {0/orange, 30/jaune, 60/jaune-vert, 90/vert, 120/bleu-vert, 150/cyan, 180/bleu roi}
{
\pgfmathparse{\ang + 15}
\xdef\ang{\pgfmathresult}
\path[postaction={decoration={
text along path,
text={ \text},
text align=center,
reverse path},
decorate}](-15+\x:4.6) arc (-15+\x :\ang :4.6);
}
\end{tikzpicture}
\end{document}
我有一个尺寸过大的错误。谢谢你的帮助!
此致。
答案1
编辑: 现在从你的回答(你应该先编辑你的问题并添加缺失的信息),我可以完成我的回答:
\documentclass[10pt,a4paper]{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows, calc, decorations.text}
\begin{document}
\begin{tikzpicture}
\foreach \x/\t [count=\xx from 0] in {%
orange/orange, jaune/yellow, jaune-vert/LimeGreen, vert/green,
bleu-vert/SeaGreen, cyan/Cyan, bleu-rois/NavyBlue, bleu/blue, violet/Violet, magenta/magenta, rouge-rosé/RubineRed, rouge/red}
{
\pgfmathsetmacro{\angle}{30*\xx}
\path[decoration={text along path,
text={\x},
text align=center,
reverse path},
postaction={decorate},
]
\ifnum\xx<7
(\angle-15:4) arc (\angle-15:\angle+15:4);
\else
(\angle+15:4.2) arc (\angle+15:\angle-15:4.2);
\fi
\draw[double=\t, semithick,
double distance=5mm] (\angle-15:3.6) arc (\angle-15:\angle+15:3.6);
\draw[semithick] (\angle-15:3.35) -- (\angle-15:3.85);
\draw[->] (0,0) -- (\angle:3);
}
\end{tikzpicture}
\end{document}
答案2
只是为了好玩,并受到示例和答案的启发,通过带有参数的定义进行安排:
\ColorWeel(<coordinate>)[<radius>][<pseudo-sharpness>]{Color_Name/Graphicx_name, Color_name/Color1!value(0-100)!color2, ...}
梅威瑟:
% By J. Leon V. Share as Beerware philosophy
\documentclass[border=20pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{kpfonts}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.text, arrows.meta}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
% Environment Cfg
>={Stealth[inset=0pt,length=10pt]}
]
%Variables: 1:Position 2:Radio 3:pseudo sharpsness 4: Name/Color array
\def\ColorWeel(#1)[#2][#3]#4{%
\begin{scope}[shift={(#1)}]
%Drawing features separations.
%\foreach \elements [count=\n] in {#4}{} %[currently the variable does not leave the loop]
\edef\Mycount{0}
\foreach \elements [count=\n] in {#4}{
\pgfmathparse{int(\Mycount+1)}
\xdef\Mycount{\pgfmathresult}
}
\pgfmathparse{int(360/\Mycount)}
\edef\Angle{\pgfmathresult}
\foreach \text/\color [count=\i from 0] in {#4}{
\draw[fill=\color,thick](\Angle*\i:#2)
arc (\Angle*\i:\Angle*\i+\Angle:#2)
-- (\Angle*\i+\Angle:#2-0.5cm) arc (\Angle*\i+\Angle:\Angle*\i:#2-0.5cm) -- cycle;
\pgfmathparse{int(\Angle*\i)}
\ifnum\pgfmathresult<180
\path[decoration={text along path,raise=-4pt,text={||\text},text align=center,reverse path},decorate]
(\Angle*\i:#2+0.5cm) arc (\Angle*\i:\Angle*\i+\Angle:#2+0.5cm);
\fi
\ifnum\pgfmathresult>179
\path[decoration={text along path,text={||\text},text align=center},decorate]
(\Angle*\i:#2+0.5cm) arc (\Angle*\i:\Angle*\i+\Angle:#2+0.5cm);
\fi
}
\clip (0,0) circle (#2-0.5cm);
\foreach \text/\color [count=\j from 0] in {#4}{
\foreach \k in {1,2,...,20}{
\path[fill=\color, opacity=#3](\Angle*\j+\Angle/2: #2-0.7cm) circle (\k*0.2);
}
\draw[thick, ->] (0,0) -- (\Angle*\j+\Angle/2: #2-1.2cm);
}
\end{scope}
}
\ColorWeel(0,0)[5cm][0.05]{
Orange/orange,
jaune/yellow,
jaune-vert/lime,
vert/green,
bleu-vert/SeaGreen,
cyan/Cyan,
bleu roi/NavyBlue,
bleu/blue,
violet/violet,
magenta/magenta,
rouge-ros{\'e}/RubineRed,
rouge/red}
\ColorWeel(11,0)[3.5cm][0.08]{
Blue/blue,
Red/red,
Yellow/yellow}
\ColorWeel(7,-10)[4cm][0.08]{
black/black,
white/white,
green-60-black/green!60!black,
blue-50-green/blue!50!green,
blue-50-red/blue!50!red}
\end{tikzpicture}
\end{document}
答案3
使用您答案中的代码,我编写了整个代码。我保留了代码的结构,但有 3 个 foreach 循环,非常适合此处。
在每个 foreach 循环中,不需要增加两个变量,只需简单地计算颜色数量并计算角度即可。
为了使代码易于阅读和理解,我拼写出了变量名称(用法语):\couleur
表示颜色\angle
,\n
表示数字。
我把颜色的尖锐重音放在rouge-ros{é}
括号之间,否则我会在编译时出错,即使使用 tikz babel 库也是如此\usetikzlibrary{babel}
inputenc 包现在包含在 LaTeX 中,不再需要加载它,所以我对其进行了评论。%\usepackage[utf8]{inputenc}
要使用 geometry 包设置相同的边距,只需编写\usepackage[margin=2cm]{geometry}
\documentclass[10pt,a4paper]{article}
%\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{kpfonts}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows,decorations.text}
\usetikzlibrary{babel}
\begin{document}
\begin{tikzpicture}
%draw names
\foreach \couleur [count=\n from 0, evaluate= \n as \angle using \n*30-15] in {orange, jaune,jaune-vert ,vert,bleu-vert,cyan,bleu-roi}
{
\path[decoration={
text along path,
text={\couleur},
text align=center,
reverse path},
postaction={decorate}]
(\angle : 4.1) arc (\angle :\angle + 30 : 4.1);
}
%% draw names
\foreach \couleur [count=\n from 7,evaluate= \n as \angle using \n*30-15] in {bleu, violet, magenta, rouge-ros{é}, rouge}
{
\path[decoration={
text along path,
text={\couleur},
text align=center},
postaction={decorate}] (\angle:4.3) arc (\angle :\angle+30:4.3);
}
\foreach \couleur [count=\n from 0, evaluate= \n as \angle using \n*30-15] in {orange, yellow,LimeGreen,green, SeaGreen, Cyan, NavyBlue, blue, Violet, magenta, RubineRed, red}
{
\draw[double=\couleur,
semithick,
double distance=5mm] (\angle:3.6) arc (\angle:\angle+30:3.6);
\draw[->,thick] (0,0) -- (\angle-15:3);
}
\end{tikzpicture}
\end{document}
答案4
我可能会从这样的事情开始:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows,decorations.text}
\begin{document}
\begin{tikzpicture}
\foreach \x/\text in
{0/orange, 1/jaune, 2/jaune-vert, 3/vert, 4/bleu-vert, 5/cyan, 6/bleu}
{
\path[postaction={decoration={text along path, text={\text},
text align=center, reverse path}, decorate}]
(30*\x - 15:6.6) arc (30*\x - 15:30*\x + 15:6.6);
}
\end{tikzpicture}
\end{document}