TikZ: dice/domino faces: loops and looks

An option following some rules, for odd numbers there should always be the midpoint, the next odd one different from the unit is the sum of the figure of the even number plus the midpoint, from number ten the pairs are the sum of the figure of number eight with the number corresponding scaling 0.5 for example 10 = 8+2(scaled 0.5) and 12=8+4(scaled 0.5), I redefined the way to draw the dice in the definition drawing \dice[point_number][color]{coordinate}, using a code like a selector, then a test drawing definition to get each dice rotated to see the symmetry...

RESULT:

enter image description here

MWE:

\documentclass[tikz,border=15pt]{standalone}

\begin{document}
    \begin{tikzpicture}
    \def\dice[#1][#2]#3#4{
        \begin{scope}[shift={(#3)},rotate=#4]
        \draw[rounded corners,fill=#2,thick](-1,1) rectangle (1,-1);
        \foreach \dice [count=\n from 1] in {
            {0/0},%1
            {45/1,-135/1},%2
            {0/0,45/1,-135/1},%3 = 2 + 1
            {45/1,135/1,-45/1,-135/1},%4 
            {0/0,45/1,135/1,-45/1,-135/1},%5 = 4+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707},%6 
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707},%7= 6+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707},%8
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707},%9 = 8+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,-135/0.5},%10 = 8+2(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,-135/0.5},%11 = 10+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5},%12=8+4(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5},%13
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353},%14=8+6(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353},%15=14+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353,90/0.353,270/0.353},%16=8+8(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353,90/0.353,270/0.353}%17=16+1
        } {
            \ifnum#1=\n 
                \foreach \k/\r in \dice {\draw[fill](\k:\r) circle (3pt);}
            \fi
        }
        \end{scope}
    }

    \def\test[#1][#2]#3{
        \begin{scope}[shift={(#3)}]
            \node[font=\sf\Huge,scale=2] at (-2,0) {#1}; 
            \dice[#1][#2]{0,0}{0}
            \dice[#1][#2]{2.2,0}{90}
            \dice[#1][#2]{4.4,0}{180}
            \dice[#1][#2]{6.6,0}{270}
        \end{scope} 
    }

    \foreach \a [count=\b] in {1,...,8}{
        \test[\a][red]{0,2.2*\b}
    }

    \foreach \a [count=\b] in {9,...,17}{
        \ifnum\a<10
            \test[\a][red]{10.8,2.2*\b}
        \else   
            \ifnum\a<13
            \test[\a][blue!50]{10.8,2.2*\b}
            \else   
            \test[\a][green!50]{10.8,2.2*\b}
            \fi
        \fi
    }

    \end{tikzpicture}
\end{document}

ADDENDUM:

Just for fun... A modification to get domino faces, new definition \domino[side1_number][side2_number][color]{position}, then a foreach code that generate the posible combinations and some conditionals to order the results in groups of 17.

RESULT:

enter image description here MWE:

\documentclass[tikz,border=15pt]{standalone}

\begin{document}
    \begin{tikzpicture}
    \def\dice[#1][#2]#3#4{
        \begin{scope}[shift={(#3)},rotate=#4]
        \foreach \dice [count=\n from 1] in {
            {0/0},%1
            {45/1,-135/1},%2
            {0/0,45/1,-135/1},%3 = 2 + 1
            {45/1,135/1,-45/1,-135/1},%4 
            {0/0,45/1,135/1,-45/1,-135/1},%5 = 4+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707},%6 
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707},%7= 6+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707},%8
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707},%9 = 8+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,-135/0.5},%10 = 8+2(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,-135/0.5},%11 = 10+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5},%12=8+4(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5},%13
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353},%14=8+6(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353},%15=14+1
            {45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353,90/0.353,270/0.353},%16=8+8(red 0.5)
            {0/0,45/1,135/1,-45/1,-135/1,0/0.707,180/0.707,90/0.707,270/0.707,45/0.5,135/0.5,-45/0.5,-135/0.5,0/0.353,180/0.353,90/0.353,270/0.353}%17=16+1
        } {
            \ifnum#1=\n 
                \foreach \k/\r in \dice {\draw[fill,#2](\k:\r) circle (3pt);}
            \fi
        }
        \end{scope}
    }

    \def\domino[#1][#2][#3]#4{
        \begin{scope}[shift={(#4)}]
        \draw[line width=1.5pt,rounded corners,top color=black!10] (-1,1) rectangle (1,-3.4);
        \dice[#1][#3!30!red]{0,0}{0}
        \dice[#2][#3!30!green]{0,-2.2}{0}
        \draw[fill] (0.8,-1) rectangle (-0.8,-1.2);
        \end{scope}
    }
    \edef\Shiftx{0}
    \edef\Shifty{0}
    \foreach \k in {0,...,16}{
        \foreach \l in {\k,...,16}{
            \domino[\l][\k][blue]{2.2*\Shiftx,5.5*\Shifty}
            \ifnum\Shiftx>15
                \pgfmathparse{int(\Shifty+1)}
                \xdef\Shifty{\pgfmathresult}
                \xdef\Shiftx{0} 
            \else
                \pgfmathparse{int(\Shiftx+1)}
                \xdef\Shiftx{\pgfmathresult}
            \fi
        }
    }
    \end{tikzpicture}
\end{document}

Without tikz. Instead, I just stack $\bullet$ bitmaps. Tile size and relative dot size may be set.

AN EXPLANATION to help decipher the gibberish:

1-9 are set on a 3x3 grid, 10-12 are [essentially] on a 4x3 grid, and 13-16 are [essentially] on a 4x4 grid. However, 11 and 13 break the rules with half steps.

In the grid layouts, \q is a dot, \z is a space, - is a linefeed. For the half-step exceptions, \Q is a dot shifted half a cell up, and \QQ is a dot shifted half up, occupying a double-wide cell.

Dots are made relatively smaller by increasing \domwd and vice versa. The actual presented size of the face is given by \domsz. Background color set with \domcolor.

\documentclass{article}
\usepackage{stackengine,scalerel,xcolor}
\newcommand\domsz{1cm}
\newcommand\domwd{23pt}
\newcommand\domcolor{white}
\newcommand\domsq{\fboxsep=0pt\fbox{\textcolor{\domcolor}{\rule{\domwd}{\domwd}}}}
\setstackEOL{-}
\newlength\dotwd
\newlength\dotht
\newcommand\q{\makebox[\dotwd]{$\bullet$}}
\newcommand\z{\makebox[\dotwd]{\phantom{$\bullet$}}}
\newcommand\Q{\raisebox{.5\dotht}{\q}}
\newcommand\QQ{\makebox[2\dotwd]{\raisebox{.5\dotht}{\q}}}
\newcommand\scaledom[2][9]{%
  \ifnum#1<13\relax%
    \setlength\dotwd{.3333\dimexpr\domwd}%
  \else
    \setlength\dotwd{.25\dimexpr\domwd}%
  \fi
  \ifnum#1<10\relax%
    \setlength\dotht{.3333\dimexpr\domwd}%
  \else
    \setlength\dotht{.25\dimexpr\domwd}%
  \fi
  \setstackgap{L}{\the\dotht}%
  \savestack\tmpbox{\stackinset{c}{}{c}{-.1ex}{\Longstack{#2}}{\domsq}}%
  \scaleto{\tmpbox}{\domsz}%
}
\newcommand\dom[1]{\csname dom#1\endcsname}
\expandafter\def\csname dom1\endcsname{\scaledom{\z\z\z-\z\q\z-\z\z\z}}
\expandafter\def\csname dom2\endcsname{\scaledom{\z\z\q-\z\z\z-\q\z\z}}
\expandafter\def\csname dom3\endcsname{\scaledom{\z\z\q-\z\q\z-\q\z\z}}
\expandafter\def\csname dom4\endcsname{\scaledom{\q\z\q-\z\z\z-\q\z\q}}
\expandafter\def\csname dom5\endcsname{\scaledom{\q\z\q-\z\q\z-\q\z\q}}
\expandafter\def\csname dom6\endcsname{\scaledom{\q\z\q-\q\z\q-\q\z\q}}
\expandafter\def\csname dom7\endcsname{\scaledom{\q\z\q-\q\q\q-\q\z\q}}
\expandafter\def\csname dom8\endcsname{\scaledom{\q\q\q-\q\z\q-\q\q\q}}
\expandafter\def\csname dom9\endcsname{\scaledom{\q\q\q-\q\q\q-\q\q\q}}
\expandafter\def\csname dom10\endcsname{%
  \scaledom[10]{\q\z\q-\q\q\q-\q\q\q-\q\z\q}}
\expandafter\def\csname dom11\endcsname{%
  \scaledom[10]{\q\q\q-\q\z\q-\q\Q\q-\q\q\q}}
\expandafter\def\csname dom12\endcsname{%
  \scaledom[12]{\q\q\q-\q\q\q-\q\q\q-\q\q\q}}
\expandafter\def\csname dom13\endcsname{%
  \scaledom[13]{\q\q\q\q-\q\z\z\q-\q\QQ \q-\q\q\q\q}}
\expandafter\def\csname dom14\endcsname{%
  \scaledom[14]{\q\q\q\q-\q\z\q\q-\q\q\z\q-\q\q\q\q}}
\expandafter\def\csname dom15\endcsname{%
  \scaledom[15]{\q\q\q\q-\q\q\q\q-\q\q\z\q-\q\q\q\q}}
\expandafter\def\csname dom16\endcsname{%
  \scaledom[16]{\q\q\q\q-\q\q\q\q-\q\q\q\q-\q\q\q\q}}
\begin{document}
\renewcommand\domcolor{red!50}\dom{1} \dom{2} \dom{3} \dom{4}\par
\dom{5} \dom{6} \dom{7} \dom{8}\par
\dom{9} \renewcommand\domcolor{blue!50}\dom{10} \dom{11} \dom{12}\par
\renewcommand\domcolor{green!50}\dom{13} \dom{14} \dom{15} \dom{16}

\medskip\renewcommand\domwd{35pt}\renewcommand\domsz{.75cm}
\dom{13} \dom{14} \dom{15} \dom{16}
\end{document}

enter image description here


Here is a version of your code that avoids nesting of tikzpictures, which also contains some minor changes. Whether my choices of placing the dots are "more symmetric" is probably a matter of taste. I also removed shapes and xcolor as you didn't use them.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\tikzset{%
  dot hidden/.style={},
  line hidden/.style={},
  dot colour/.style={dot hidden/.append style={color=#1}},
  dot colour/.default=black,
  line colour/.style={line hidden/.append style={color=#1}},
  line colour/.default=black,
}%
\usepackage{xparse}
\tikzset{pics/.cd,
dice/.style args={#1/#2}{code={
\draw[rounded corners=1,line hidden,#1] (0,0) rectangle (1,1);
\ifnum#2<10% "standard die"
  \ifodd#2
    \fill[dot hidden] (0.5,0.5) circle(1.5pt);% 1,3,5,7,9
  \fi
  \ifnum#2>1
    \fill[dot hidden] (0.15,0.15) circle(1.5pt);% 2
    \fill[dot hidden] (0.85,0.85) circle(1.5pt);% 3
    \ifnum#2>3
      \fill[dot hidden] (0.15,0.85) circle(1.5pt);% 4
      \fill[dot hidden] (0.85,0.15) circle(1.5pt);% 5
      \ifnum#2>5
        \fill[dot hidden] (0.85,0.5) circle(1.5pt);% 5
        \fill[dot hidden] (0.15,0.5) circle(1.5pt);% 6
        \ifnum#2>7
          \fill[dot hidden] (0.5,0.85) circle(1.5pt);% 7
          \fill[dot hidden] (0.5,0.15) circle(1.5pt);% 8
        \fi
      \fi
    \fi
  \fi
\fi
\ifnum#2>9% "extended die"
  \ifnum#2<13% 
    \fill[dot hidden] (0.15,0.15) circle(1.5pt);
    \fill[dot hidden] (0.15,0.85) circle(1.5pt);
    \fill[dot hidden] (0.85,0.15) circle(1.5pt);
    \fill[dot hidden] (0.85,0.85) circle(1.5pt);
    \fill[dot hidden] (0.15,0.38) circle(1.5pt);
    \fill[dot hidden] (0.15,0.61) circle(1.5pt);
    \fill[dot hidden] (0.85,0.38) circle(1.5pt);
    \fill[dot hidden] (0.85,0.61) circle(1.5pt);
    \ifodd#2
      \fill[dot hidden] (0.50,0.50) circle(1.5pt);
      \fill[dot hidden] (0.50,0.15) circle(1.5pt);
      \fill[dot hidden] (0.50,0.85) circle(1.5pt);
    \else
      \fill[dot hidden] (0.50,0.15) circle(1.5pt); %<-changed
      \fill[dot hidden] (0.50,0.85) circle(1.5pt); %<-changed
    \fi
    \ifnum#2>11
      \fill[dot hidden] (0.50,0.38) circle(1.5pt); 
      \fill[dot hidden] (0.50,0.61) circle(1.5pt); 
    \fi
  \else % here #2 > 12
    \fill[dot hidden] (0.15,0.15) circle(1.5pt);
    \fill[dot hidden] (0.15,0.85) circle(1.5pt);
    \fill[dot hidden] (0.85,0.15) circle(1.5pt);
    \fill[dot hidden] (0.85,0.85) circle(1.5pt);
    \fill[dot hidden] (0.15,0.38) circle(1.5pt);
    \fill[dot hidden] (0.15,0.61) circle(1.5pt);
    \fill[dot hidden] (0.85,0.38) circle(1.5pt);
    \fill[dot hidden] (0.85,0.61) circle(1.5pt);  
    \ifnum#2=14
      \fill[dot hidden] (0.38,0.27) circle(1.5pt);
      \fill[dot hidden] (0.61,0.27) circle(1.5pt);
      \fill[dot hidden] (0.38,0.50) circle(1.5pt);
      \fill[dot hidden] (0.61,0.50) circle(1.5pt);
      \fill[dot hidden] (0.38,0.73) circle(1.5pt);
      \fill[dot hidden] (0.61,0.73) circle(1.5pt);
    \else
      \fill[dot hidden] (0.38,0.15) circle(1.5pt);
      \fill[dot hidden] (0.38,0.85) circle(1.5pt);
      \fill[dot hidden] (0.61,0.15) circle(1.5pt);
      \fill[dot hidden] (0.61,0.85) circle(1.5pt);
    \fi
    \ifnum#2<14
      \fill[dot hidden] (0.50,0.50) circle(1.5pt); 
    \fi
    \ifnum#2>14
      \fill[dot hidden] (0.38,0.61) circle(1.5pt);
      \fill[dot hidden] (0.61,0.61) circle(1.5pt); 
      \ifnum#2=15      
        \fill[dot hidden] (0.5,0.38) circle(1.5pt);        
      \fi   
      \ifnum#2>15
          \fill[dot hidden] (0.38,0.38) circle(1.5pt);
          \fill[dot hidden] (0.61,0.38) circle(1.5pt);
      \fi
    \fi
  \fi
\fi}}
}%

\begin{document}
\begin{tikzpicture}[A/.style={fill=red!70},B/.style={fill=blue!50},
C/.style={fill=green!50}]
\matrix[column sep=3pt,row sep=4pt]{%
\pic {dice=A/1};   & \pic {dice=A/2};   & \pic {dice=A/3};   & \pic {dice=A/4}; \\
\pic {dice=A/5};   & \pic {dice=A/6};   & \pic {dice=A/7};   & \pic {dice=A/8}; \\
\pic {dice=A/9};   & \pic {dice=B/10}; & \pic {dice=B/11}; & \pic {dice=B/12}; \\
\pic {dice=C/13}; & \pic {dice=C/14}; & \pic {dice=C/15}; & \pic {dice=C/16}; \\
}; 
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf