\usepackage{ifthen}

\def\size{3}
\def\frontScale{0.75}
\def\leftScale{1.0}
\def\rightScale{1.0}
\def\frontCos{0.61}
\def\leftCos{0.94}
\def\rightCos{0.94}
\def\frontSin{0.44}
\def\leftSin{0.34}
\def\rightSin{0.34}

\newcommand\computeFront[2]
{
  \edef\frontScale{#2}
  \pgfmathparse{cos(#1)*\frontScale}
  \edef\frontCos{\pgfmathresult}
  \pgfmathparse{sin(#1)*\frontScale}
  \edef\frontSin{\pgfmathresult}  
}

\newcommand\computeLeft[2]
{
  \edef\leftScale{#2}
  \pgfmathparse{cos(#1)*\leftScale}
  \edef\leftCos{\pgfmathresult}
  \pgfmathparse{sin(#1)*\leftScale}
  \edef\leftSin{\pgfmathresult}  
}

\newcommand\computeRight[2]
{
  \edef\rightScale{#2}
  \pgfmathparse{cos(#1)*\rightScale}
  \edef\rightCos{\pgfmathresult}
  \pgfmathparse{sin(#1)*\rightScale}
  \edef\rightSin{\pgfmathresult}  
}

\newcommand\frontdice[4]
% #1, #2 - współrzędne prawego dolnego wierzchołka
% #3 - liczby kropek i kolor ścian na widocznych ścianach kostki, w kolejności: prawa, przednia, górna
% #4 - kolor kropek
{
  \setcounter{nr}{0}
  \foreach \i/\j in #3
  {
    \addtocounter{nr}{1}
    \pgftransformreset
    \ifthenelse{\value{nr} = 1}{\pgftransformcm{\frontCos*\size}{\frontSin*\size}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 2}{\pgftransformcm{-1*\size}{0}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 3}{\pgftransformcm{\frontCos*\size}{\frontSin*\size}{-1*\size}{0}{\pgfpoint{#1cm}{#2cm + \size cm}}}{}
    \face{#4}{\j}{\i}
  }
}

\newcommand\unroundedfrontdice[4]
% #1, #2 - współrzędne prawego dolnego wierzchołka
% #3 - liczby kropek i kolor ścian na widocznych ścianach kostki, w kolejności: prawa, przednia, górna
% #4 - kolor kropek
{
  \setcounter{nr}{0}
  \foreach \i/\j in #3
  {
    \addtocounter{nr}{1}
    \pgftransformreset
    \ifthenelse{\value{nr} = 1}{\pgftransformcm{\frontCos*\size}{\frontSin*\size}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 2}{\pgftransformcm{-1*\size}{0}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 3}{\pgftransformcm{\frontCos*\size}{\frontSin*\size}{-1*\size}{0}{\pgfpoint{#1cm}{#2cm + \size cm}}}{}
    \unroundedface{#4}{\j}{\i}
  }
}

\newcommand\dice[4]
% #1, #2 - współrzędne prawego dolnego wierzchołka
% #3 - liczby kropek i kolor ścian na widocznych ścianach kostki, w kolejności: prawa, przednia, górna
% #4 - kolor kropek
{
  \setcounter{nr}{0}
  \foreach \i/\j in #3
  {
    \addtocounter{nr}{1}
    \pgftransformreset
    \ifthenelse{\value{nr} = 1}{\pgftransformcm{\rightCos*\size}{\rightSin*\size}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 2}{\pgftransformcm{-\leftCos*\size}{\leftSin*\size}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 3}{\pgftransformcm{\rightCos*\size}{\rightSin*\size}{-\leftCos*\size}{\leftSin*\size}{\pgfpoint{#1cm}{#2cm + \size cm}}}{}
    \face{#4}{\j}{\i}
  }
}

\newcommand\unroundeddice[4]
% #1, #2 - współrzędne prawego dolnego wierzchołka
% #3 - liczby kropek i kolor ścian na widocznych ścianach kostki, w kolejności: prawa, przednia, górna
% #4 - kolor kropek
{
  \setcounter{nr}{0}
  \foreach \i/\j in #3
  {
    \addtocounter{nr}{1}
    \pgftransformreset
    \ifthenelse{\value{nr} = 1}{\pgftransformcm{\rightCos*\size}{\rightSin*\size}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 2}{\pgftransformcm{-\leftCos*\size}{\leftSin*\size}{0}{\size}{\pgfpoint{#1cm}{#2cm}}}{}
    \ifthenelse{\value{nr} = 3}{\pgftransformcm{\rightCos*\size}{\rightSin*\size}{-\leftCos*\size}{\leftSin*\size}{\pgfpoint{#1cm}{#2cm + \size cm}}}{}
    \unroundedface{#4}{\j}{\i}
  }
}

\newcommand\unroundedface[3]
% #1 - kolor kropek
% #2 - kolor tła
% #3 - liczba kropek
{
  \fill[fill = #2] rectangle(1, 1);
  \draw rectangle(1, 1);
  \ifthenelse{#3 = 1}{\onedot{#1}}{}
  \ifthenelse{#3 = 2}{\twodots{#1}}{}
  \ifthenelse{#3 = 3}{\threedots{#1}}{}
  \ifthenelse{#3 = 4}{\fourdots{#1}}{}
  \ifthenelse{#3 = 5}{\fourdots{#1}, \onedot{#1}}{}
  \ifthenelse{#3 = 6}{\sixdots{#1}}{}
}

\newcommand\face[3]
% #1 - kolor kropek
% #2 - kolor tła
% #3 - liczba kropek
{
  \fill[fill = #2, rounded corners] rectangle(1, 1);
  \draw[rounded corners] rectangle(1, 1);
  \ifthenelse{#3 = 1}{\onedot{#1}}{}
  \ifthenelse{#3 = 2}{\twodots{#1}}{}
  \ifthenelse{#3 = 3}{\threedots{#1}}{}
  \ifthenelse{#3 = 4}{\fourdots{#1}}{}
  \ifthenelse{#3 = 5}{\fourdots{#1}, \onedot{#1}}{}
  \ifthenelse{#3 = 6}{\sixdots{#1}}{}
}

\newcommand\onedot[1]
% #1 - kolor tła
{
  \fill[fill = #1, shift = {(0.5, 0.5)}] circle[radius = 0.05];
}

\newcommand\twodots[1]
% #1 - kolor tła
{
  \foreach \offset in {0.3, 0.7}
    \fill[fill = #1, shift = {(\offset, \offset)}] circle[radius = 0.05];
}

\newcommand\threedots[1]
% #1 - kolor tła
{
  \foreach \offset in {0.25, 0.5, 0.75}
    \fill[fill = #1, shift = {(\offset, \offset)}] circle[radius = 0.05];
}

\newcommand\fourdots[1]
% #1 - kolor tła
{
  \foreach \offset in {0.3, 0.7}
  {
    \fill[fill = #1, shift = {(\offset, \offset)}] circle[radius = 0.05];
    \fill[fill = #1, shift = {(\offset, 1 - \offset)}] circle[radius = 0.05];
  }
}

\newcommand\sixdots[1]
% #1 - kolor tła
{
  \foreach \xoffset in {0.3, 0.7}
    \foreach \yoffset in {0.25, 0.5, 0.75}
      \fill[fill = #1, shift = {(\xoffset, \yoffset)}] circle[radius = 0.05];
}

