答案1
只是为了好玩,使用条件、绘图定义和嵌套指令优化以前帖子中的代码。
梅威瑟:
% By J. Leon, Beerware licence is acceptable...
\documentclass[tikz, border=15pt]{standalone}
\usepackage{xcolor} % For custom colors using color pickers.
\definecolor{CustA}{RGB}{228, 127, 226}
\definecolor{CustB}{RGB}{127, 211, 125}
\definecolor{CustC}{RGB}{204, 174, 161}
\definecolor{CustD}{RGB}{248, 185, 126}
\definecolor{CustE}{RGB}{255, 127, 125}
\definecolor{CustF}{RGB}{226, 127, 141}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}
\begin{document}
\begin{tikzpicture}[
%Environment Configuration
font=\Large, %unworn but ready for action
%Styles
Line/.style = {% Style for lines
line width=4mm,
line cap=round,
%opacity=0.5
},
Area/.style = {% Style for shaded areas
line width=4mm,
fill,
line cap=round,
rounded corners= 0.5mm,
%opacity=0.5
}
]
% Start drawing "the thing..."
%Create a drawing definition \Mshape(position)[rotatión]{state}
\def\Mshape(#1)[#2]#3{
\begin{scope}[shift={(#1)},rotate=#2]
\foreach \k in {1,...,5}{
\draw[fill](72*\k-36:1cm) circle (1mm) coordinate (N\k);
}
\begin{scope}[on background layer] % Conditional drawings in the background.
\ifnum#3=1 \draw[Line,CustA](N3) -- (N4); \fi
\ifnum#3=2 \draw[Line,CustA](N2) -- (N5); \fi
\ifnum#3=3 \draw[Area,CustB](N1) -- (N3) -- (N4) -- cycle; \fi
\ifnum#3=4 \draw[Area,CustB](N5) -- (N1) -- (N2) -- cycle; \fi
\ifnum#3=5 \draw[Line,CustC](N2) -- (N3); \draw[Line,CustD](N4) -- (N5); \fi
\ifnum#3=6 \begin{scope}[blend group=multiply]\draw[Line,CustC](N2) -- (N4); \draw[Line,CustD](N3) -- (N5); \end{scope}\fi
\ifnum#3=7 \draw[Line,CustC](N3) -- (N4); \draw[Line,CustD](N5) -- (N2); \fi
\ifnum#3=8 \draw[Area,CustE](N2) -- (N3) -- (N4) -- (N5) -- cycle; \fi
\ifnum#3=9 \draw[Line,CustA](N3) -- (N4); \draw[Area,CustB](N5) -- (N1) -- (N2) -- cycle; \fi
\ifnum#3=10 \begin{scope}[blend group=multiply]\draw[Line,CustA](N2) -- (N5); \draw[Area,CustB](N1) -- (N3) -- (N4) -- cycle; \end{scope}\fi
\ifnum#3=11 \draw[Area,CustE](N1) -- (N2) -- (N3) -- (N4) -- (N5) -- cycle; \fi
\end{scope}
\end{scope}
}
\Mshape(0,0)[0]{0} % first drawing at origin
\foreach \Rot [count=\Yshift from 0] in {1,...,5}{ %copies are made downward and rotating
\foreach \case [count=\Xshift from 0]in {1,...,10}{ %copies of the various cases are made forward
\Mshape(3cm+3cm*\Xshift,-6cm+3cm*\Yshift)[0-72*\Rot]{\case}
}
}
\Mshape(33cm,0)[0]{11} % last drawing with case 11
\end{tikzpicture}
\end{document}
答案2
我对我提供的解决方案并不完全满意,但这是一个开始。
它还没有完成,但你明白了。
不幸的是,它还不够通用,不符合我的口味,我可能会努力改进它。
\documentclass{article}
\usepackage{tikz}
\definecolor{2purple}{RGB}{204,102,255}
\definecolor{3green}{RGB}{0,204,0}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\tikzset{twopurple/.style={2purple,line width=8pt,rounded corners=2pt,cap=round}}
\tikzset{threegreen/.style={3green,line width=8pt,rounded corners=2pt,cap=round,fill}}
\newcommand{\pent}
{
\foreach \i in {1,...,5}
{
\coordinate (p\i) at (72*\i:\r);
\filldraw(p\i) circle (\pointradius pt);
}
}
\def\r{1} % pentagon radius
\def\pointradius{3} % points radius
% First row
\foreach \j/\k [count=\shft from 0] in
{1/2,
2/3,
3/4,
4/5,
5/1}
{
\begin{scope}[yshift=-100*\shft]
\pent
\foreach \i in {1,...,5}
\draw[twopurple] (p\j) -- (p\k);
\pent
\end{scope}
}
% Second row
\foreach \j/\k [count=\shft from 0] in
{3/5,
1/4,
2/5,
1/3,
2/4}
{
\begin{scope}[xshift=100,yshift=-100*\shft]
\pent
\foreach \i in {1,...,5}
\draw[twopurple] (p\j) -- (p\k);
\pent
\end{scope}
}
% Third row
\foreach \j/\k/\l [count=\shft from 0] in
{1/2/3,
2/3/4,
3/4/5,
4/5/1,
5/1/2}
{
\begin{scope}[xshift=200,yshift=-100*\shft]
\pent
\foreach \i in {1,...,5}
\draw[threegreen] (p\j) -- (p\k) -- (p\l) -- cycle;
\pent
\end{scope}
}
% Fourth row
\foreach \j/\k/\l [count=\shft from 0] in
{1/2/4,
2/3/5,
3/4/1,
4/5/2,
5/1/3}
{
\begin{scope}[xshift=300,yshift=-100*\shft]
\pent
\foreach \i in {1,...,5}
\draw[threegreen] (p\j) -- (p\k) -- (p\l) -- cycle;
\pent
\end{scope}
}
\end{tikzpicture}
\end{document}
答案3
类似这样的事情可能是一个起点:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=5, minimum size=2cm] (A){};
\filldraw[line width=3pt, green, line join=round] (A.corner 1)--(A.corner 2)--(A.corner 4)--(A.corner 5)--cycle;
\foreach \i in {1,2,...,5}
\filldraw (A.corner \i) circle(1pt);
\end{tikzpicture}
\end{document}