Drawing dice with rounded corners simulation

tikz-pgf

I use the following code from this post, to draw dice simulation.

\documentclass[12pt,a4paper]{article}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
 \begin{scope}[canvas is xy plane at z=3]
  \path[draw=none, fill=brown!50!white] (-3,-3) rectangle (3,3);
  \path (0,0) [line cap=round, line join=round, line width=0.9cm, rounded corners=0.9cm, inner color=green!70!black, outer color=green!70!black, rotate=18+90,transform shape] circle (2.cm);
 \end{scope}
 \begin{scope}[canvas is xz plane at y=3]
  \path[draw=none, fill=brown!70!white] (-3,-3) rectangle (3,3);
  \path (0,0) [line cap=round, line join=round, line width=0.9cm, rounded corners=0.9cm, inner color=yellow, outer color=yellow, rotate=18,transform shape] circle (2.cm);
 \end{scope}
 \begin{scope}[canvas is yz plane at x=3]
  \path[draw=none, fill=brown!80!white] (-3,-3) rectangle (3,3);
  \path (0,0) [line cap=round, line join=round, line width=0.9cm, rounded corners=0.9cm, inner color=red, outer color=red, rotate=18,transform shape] circle (2.cm);
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

How can I put this code in a style, to be repeated in different locations of the document, with different rotation angles.

Also how can I make this cube looks like a die, with controllable rounded corners.

enter image description here

Best Answer

I only made it, so that the angles work with the sides in the same order, but it could be made conditional dependent on the angle.

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\begin{tikzpicture}
\newcommand{\dice}[5]{
\tdplotsetmaincoords{#3}{#4}
\begin{scope}[shift={(#1,#2)}, tdplot_main_coords, rounded corners=#5, fill=brown!50!white]
\begin{scope}[canvas is xy plane at z=-1]
\filldraw (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is xz plane at y=-1]
\filldraw (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is yz plane at x=-1]
\filldraw (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=1]
\filldraw (-1,-1) rectangle (1,1);
\fill[green!70!black] circle[radius=2/3];
\end{scope}
\begin{scope}[canvas is xz plane at y=1]
\filldraw (-1,-1) rectangle (1,1);
\fill[yellow] circle[radius=2/3];
\end{scope}
\begin{scope}[canvas is yz plane at x=1]
\filldraw (-1,-1) rectangle (1,1);
\fill[red] circle[radius=2/3];
\end{scope}
\end{scope}
}
\dice{0}{0}{70}{110}{0.3cm};
\dice{2}{2}{70}{110}{0.5cm};
\dice{5}{3}{40}{130}{0.3cm};
\dice{5}{-1}{40}{160}{0.6cm};
\end{tikzpicture}
\end{document}

Dices with color sides