Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
\documentclass{article}
\usepackage{tikz}
\tikzset{
star graph/.pic={
\node[
fill,
inner sep=0pt,
outer sep=0pt,
circle,
minimum size=\pgfkeysvalueof{/tikz/star graph/vertex size},
node contents={},
at={(0,0)},
name=centre,
star graph/every vertex/.try,
star graph/centre/.try,
];
\foreach \n in {1,...,#1} {
\node[
fill,
inner sep=0pt,
outer sep=0pt,
circle,
minimum size=\pgfkeysvalueof{/tikz/star graph/vertex size},
node contents={},
at={({\n*360/#1 + \pgfkeysvalueof{/tikz/star graph/start angle}}:\pgfkeysvalueof{/tikz/star graph/edge size})},
name=vertex \n,
star graph/every vertex/.try=\n,
star graph/vertex \n/.try=\n
];
\draw[
star graph/every edge/.try=\n,
star graph/edge \n/.try=\n
] (centre) -- (vertex \n);
}
},
star graph/.is family,
star graph/.cd,
vertex size/.initial=10pt,
edge size/.initial=3cm,
start angle/.initial=0
}
\begin{document}
\begin{tikzpicture}
\pic[
star graph/.cd,
every edge/.style={
red,
ultra thick,
},
every vertex/.style={
blue,
label={#1}
},
centre/.style={
purple
},
start angle=30
] {star graph=5};
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.