# Different color for certain dice rolls \[2d6\]

**URL:** <https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087>\
**Category:** Module Design\
**Created:** [December 10, 2024, 2:57am UTC](https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087 "2024-12-10T02:57:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saigon](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/saigon/32/10716_2.png) [@Saigon](https://forum.vassalengine.org/u/Saigon)\
**Post date:** [December 10, 2024, 2:57am UTC](https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087/1 "2024-12-10T02:57:43Z")

</div>

I’m still setting up this tennis game and I’d love to accent the _interesting_ dice rolls.

There are 3 results that I’d like to have a different color:

- Doubles.
- Any roll of a 7.
- A roll of 12.

Any other roll is plain.

There are 36 possible results with 2d6 and I once made a 1d36 table with all the different dice rolls listed, this table I had it report the dice roll and the result.  
But I’m not sure how to change the color for these specific rolls.

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [December 10, 2024, 10:18am UTC](https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087/2 "2024-12-10T10:18:07Z")

</div>

Hi,

> [@Saigon](#):
>
> There are 36 possible results with 2d6 and I once made a 1d36 table with all the different dice rolls listed, this table I had it report the dice roll and the result.  
> But I’m not sure how to change the color for these specific rolls.

You probably need a [`Symbolic Dice Button`](https://vassalengine.org/doc/latest/ReferenceManual/SpecialDiceButton.html) with 36 different images that highlight the interesting rolls. For example

 ![dice](https://forum.vassalengine.org/uploads/default/original/2X/8/8aba2593bf0e6725c62c80a94e1a0f37f5f11441.png)

This was made with LATEX and my [`wargame`](https://wargames_tex.gitlab.io/wargame_www/tools.html) package (shameless self-plug 😄 ) with the code

```auto
\documentclass[tikz]{standalone}

\usepackage{wargame}

\tikzset{
  die/.style={
    shape=d6,
    scale line widths,
    line width=1pt,
    transform shape,
    scale=.7
  },
  fg die/.style args={#1,#2}{
    die,
    fill=#1,
    text=#2,
    font=\sffamily\bfseries\Large,
    draw=gray!25!white},
  die shadow/.style={
    die,
    fill=black,
    draw=none,
    opacity=.5}
}  
\newcommand\DiceExample[4]{%
  %\begin{tikzpicture}[
  \node[die shadow,rotate=10] (s1) at (.40,.07){};
  \node[die shadow,rotate=-10] (s2) at (-.25,-.11){};
  \node[fg die={#1,#2}, rotate=10] at ($(s1)+(-.05,.03)$) {#3};
  \node[fg die={#1,#2}, rotate=-10] at ($(s2)+(-.05,.04)$) {#4};
  \draw(-.7,-.5)rectangle(.8,.5);}

\begin{document}
\begin{tikzpicture}
\foreach \n in {1,2,...,6}{
  \foreach \m in {1,2,...,6}{
    \pgfmathparse{int(\n+\m)}\edef\s{\pgfmathresult}
    \def\bg{white}\def\fg{black}
    \ifnum\n=\m\def\bg{red}\def\fg{white}\fi
    \ifnum\s=7\def\bg{blue}\def\fg{white}\fi
    \ifnum\s=12\def\bg{green}\def\fg{white}\fi
    \begin{scope}[shift={(1.5*\n,\m)}]
      \DiceExample{\bg}{\fg} {\n}{\m}
    \end{scope}
  }
}
\end{tikzpicture}
\end{document}

```

[`Symbolic Dice Button`](https://vassalengine.org/doc/latest/ReferenceManual/SpecialDiceButton.html) lets you define any discrete probability mass function (pmf) by supplying an image for each possible outcome and assigning a value to that. Thus, you can build a 2d6 pmf - which is a _triangular_ distribution, not a normal, or “bell”, distribution - by supplying 36 images and assign appropriate values to each.

One can also use [`Symbolic Dice Button`](https://vassalengine.org/doc/latest/ReferenceManual/SpecialDiceButton.html) to define a “loaded” die. Some gamers feel that “extreme” outcomes are more probable in some games than they ought to be. In that case, one can make an option where the probability mass function is more triangular - e.g.,

| x | P(x) |
| --- | --- |
| 1 | 1 / 12 |
| 2 | 2 / 12 |
| 3 | 3 / 12 |
| 4 | 3 / 12 |
| 5 | 2 / 12 |
| 6 | 1 / 12 |

I have something like that - as an option - in my [Gettysburg - Smithsonian Edition](https://vassalengine.org/wiki/Module:Gettysburg:_125th_Anniversary_Edition) module (`ch-1.x`).

Hope that helps.

Yours,  
_Christian_

---

<div class="post-metadata">

**Author:** ![Saigon](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/saigon/32/10716_2.png) [@Saigon](https://forum.vassalengine.org/u/Saigon)\
**Post date:** [December 10, 2024, 12:37pm UTC](https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087/3 "2024-12-10T12:37:07Z")

</div>

This is really epic!  
So i would make a symbolic dice button, add the 36 dice roll combinations, and put that piece of code in?

Thanks and I’ll check out your module too.

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [December 10, 2024, 3:09pm UTC](https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087/4 "2024-12-10T15:09:39Z")

</div>

Just to be explicit and clear

> [@Saigon](#):
>
> So i would make a symbolic dice button, …

Correct

> [@Saigon](#):
>
> … add the 36 dice roll combinations, …

Correct, each with it’s own image (cut out from the image above or make your own)

> [@Saigon](#):
>
> … and put that piece of code in?

Depends on what you mean by “that … code”. If you mean

```auto
\documentclass[tikz]{standalone}

\usepackage{wargame}
...
\end{document}

```

then _no_. That code is [LATEX](https://latex.net) code that simply produces the image above. In case you don’t know, LATEX is a typesetting system for producing high-quality, publication-ready manuscripts - particularly suitable and used for articles in journals of Natural Science. As such, LATEX has nothing to do with VASSAL or [BeanShell](http://www.beanshell.org/).

**Aside**  
My LATEX package [`wargame`](https://wargames_tex.gitlab.io/wargame_www/tools.html) can take a LATEX document and make a (draft) VASSAL module via an intermittent Python script ([`pywargame`](https://wargames_tex.gitlab.io/wargame_www/tools.html)).

What you need is

- A [`Symbolic Dice Button`](https://vassalengine.org/doc/latest/ReferenceManual/SpecialDiceButton.html) - check `show result in window` -
  - with a single [`Symbolic Dice`](https://vassalengine.org/doc/latest/ReferenceManual/SpecialDiceButton.html#_symbolic_die)
    - with 32 [`Symbolic Dice Face`](https://vassalengine.org/doc/latest/ReferenceManual/SpecialDiceButton.html#_symbolic_die_face)
      - Each face has a single image (one of the 32 rectangles from above) that illustrates the result, and
      - `Numerical value` value set to the value of the roll

If you know LATEX, you can easily customise the dice colours above. In

```auto
    \def\bg{white}\def\fg{black}
    \ifnum\n=\m\def\bg{red}\def\fg{white}\fi
    \ifnum\s=7\def\bg{blue}\def\fg{white}\fi
    \ifnum\s=12\def\bg{green}\def\fg{white}\fi

```

- The first line sets the default background to white (`\def\bg{white}`) and foreground to black (`\def\fg{black}`)
- The second line sets the background to `red` and foreground to `white` when the two die are equal
- The third line sets the background to `blue` and foreground to `white` when the sum of the dice is 7
- The fourth line sets the background to `green` and foreground to `white` when the sum is 12.

You can change these colours however you like - for example, to make a darker red, mix 50% red with 50% black by `red!50!black`. Suppose you save the above code in a file called `dice.tex`, then you can run LATEX on it with

```auto
$ pdflatex dice.tex 

```

to produce `dice.pdf`. This in turn can be made into PNG(s) with

```auto
$ pdftocairo -singlefile -png dice.pdf -o dice

```

or f.ex. [Gimp](https://gimp.org). If you modify the above LATEX code like

```auto
\documentclass[tikz]{standalone}

\usepackage{wargame}

\tikzset{
  die/.style={
    shape=d6,
    scale line widths,
    line width=1pt,
    transform shape,
    scale=.7
  },
  fg die/.style args={#1,#2}{
    die,
    fill=#1,
    text=#2,
    font=\sffamily\bfseries\Large,
    draw=gray!25!white},
  die shadow/.style={
    die,
    fill=black,
    draw=none,
    opacity=.5}
}  
\newcommand\DiceExample[4]{%
  %\begin{tikzpicture}[
  \node[die shadow,rotate=10] (s1) at (.40,.07){};
  \node[die shadow,rotate=-10] (s2) at (-.25,-.11){};
  \node[fg die={#1,#2}, rotate=10] at ($(s1)+(-.05,.03)$) {#3};
  \node[fg die={#1,#2}, rotate=-10] at ($(s2)+(-.05,.04)$) {#4};
}

\begin{document}
\nopagecolor
\foreach \n in {1,2,...,6}{
  \foreach \m in {1,2,...,6}{
    \pgfmathparse{int(\n+\m)}\edef\s{\pgfmathresult}
    \def\bg{white}\def\fg{black}
    \ifnum\n=\m\def\bg{red}\def\fg{white}\fi
    \ifnum\s=7\def\bg{blue}\def\fg{white}\fi
    \ifnum\s=12\def\bg{green}\def\fg{white}\fi
    \begin{tikzpicture}
        \DiceExample{\bg}{\fg} {\n}{\m}
    \end{tikzpicture}
  }
}
\end{document}

```

you will get a PDF with 36 “pages” - each correspond to a die combination, which you can then turn into individual PNGs (named `dice-00.png`, `dice-01.png`, …, `dice-35.png`) with

```auto
$ pdftocairo -png dice.pdf -o dice

```

which you can directly import into your VASSAL module.

Yours,  
_Christian_

---

<div class="post-metadata">

**Author:** ![Saigon](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/saigon/32/10716_2.png) [@Saigon](https://forum.vassalengine.org/u/Saigon)\
**Post date:** [December 11, 2024, 1:54pm UTC](https://forum.vassalengine.org/t/different-color-for-certain-dice-rolls-2d6/84087/5 "2024-12-11T13:54:38Z")

</div>

Thank you this has all been very helpful
