This question is vagely related to https://math.stackexchange.com/questions/3449433/selecting-cards-to-form-a-fair-game?noredirect=1#comment7090962_3449433. I am trying to visually illustrate the ways one can draw 3 balls from a pile of N+M
balls,
where N
is the number of blue and M
is the number of green.
My attempt at doing this in tikz can be seen below. Here I first arrange the balls in order, and then show how they appear when one ball is removed. A line between two balls indicates that these two balls are choosen PLUS the dotted ball.
There are some changes I would like to do however.
- So we pick 3 balls, the two connected by the line PLUS the dotted one. If these three balls have the same color, I want the line connecting them to be in style X (dashed, or red or etc)
- If the three balls have different colors, I want the line connecting them to be in style Y (solid line, orange, or etc)
- Why does my code fail for the particular case
2
? - Is there a way to make the code work for different number of blue and green balls?
- How can I pick the rotation of the center polygon so that it matches with the corners of the outer one? Now I changed the inner one to manually fit.
Is there a particular reason the code below does not work?
\foreach \x in {1,...,\n}{ \begin{scope}[shift={(b.corner \x)}] \missingPentagonTemp{2}{c}; \end{scope} }
Here is what I want it to look like (courtesy of paint).
MWE
\documentclass[a4paper,11pt,margin=5pt]{standalone}
\usepackage{tikz,xcolor}
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations}
\usepackage{ifthenx}
\newcommand{\missingPentagon}[2]{
% draw edges
\node[draw=none, minimum size=3cm, regular polygon, regular polygon sides = \n] (#2) {};
\def\n{6}
\pgfmathsetmacro{\start}{int(min(#1+1, \n))};
\pgfmathsetmacro{\stop}{int(max(#1-1, 2))};
\ifthenelse{\equal{#1}{1}}{
\foreach\x in{2,...,\n}{
\foreach\y in{\x,...,\n}{
\draw[color = black, dashed](#2.corner \x)--(#2.corner \y);
}
}
\foreach \x in {1}{
\draw[fill=green!20,dashed](#2.corner \x) circle[radius=1em] node {\x};
}
\foreach \x in {2,...,\n}{
\draw[fill=blue!20](#2.corner \x) circle[radius=1em] node {\x};
}
}{
\foreach\x in {1,...,\stop}{
\foreach\y in {\x,...,\n}{
\ifthenelse{\equal{#1}{\y}}{}{
\draw[color = black, dashed](#2.corner \x) -- (#2.corner \y)};
}
}
\foreach\x in {\start,...,\n}{
\foreach\y in {\x,...,\n}{
\ifthenelse{\equal{#1}{\y}}{}{
\draw[color = black, dashed](#2.corner \x) -- (#2.corner \y)};
}
}
\foreach \x in {1}{
\draw[fill=green!20](#2.corner \x) circle[radius=1em] node {\x};
}
\foreach \x in {2,...,\n}{
\ifthenelse{\equal{#1}{\x}}{
\draw[fill=blue!20,dashed](#2.corner \x) circle[radius=1em] node {\x};
}{
\draw[fill=blue!20](#2.corner \x) circle[radius=1em] node {\x};
};
}
}
}
\begin{document}
\begin{tikzpicture}
\def\n{6}
\node[draw=none, minimum size=3cm, regular polygon, regular polygon sides = \n] (a) {};
\node[draw=none, minimum size=10cm, regular polygon, regular polygon sides = \n] (b) {};
\foreach \x in {4}{
\draw[fill=green!20](a.corner \x) circle[radius=1em] node {1};
}
\foreach \x in {1,...,3}{
\pgfmathparse{int(\x+3)}
\draw[fill=blue!20](a.corner \x) circle[radius=1em] node {\pgfmathresult};
}
\foreach \x in {5,...,6}{
\pgfmathparse{int(\x-3)}
\draw[fill=blue!20](a.corner \x) circle[radius=1em] node {\pgfmathresult};
}
%\foreach \x in {1,...,\n}{
% \begin{scope}[shift={(b.corner \x)}]
% \missingPentagonTemp{2}{c};
% \end{scope}
%}
\begin{scope}[shift={(b.corner 1)}]
\missingPentagon{4}{c};
\end{scope}
\begin{scope}[shift={(b.corner 2)}]
\missingPentagon{5}{c};
\end{scope}
\begin{scope}[shift={(b.corner 3)}]
\missingPentagon{6}{c};
\end{scope}
\begin{scope}[shift={(b.corner 4)}]
\missingPentagon{1}{c};
\end{scope}
\begin{scope}[shift={(b.corner 5)}]
\missingPentagon{2}{c};
\end{scope}
\begin{scope}[shift={(b.corner 6)}]
\missingPentagon{3}{c};
\end{scope}
\end{tikzpicture}
\end{document}