Digitial Die
So, not too long ago, my wife picked up a “Big Bad Wolf” kids card game. I’m not having any luck finding information about it on the internet for a link, so suffice it to say that it’s a mix between Go Fish & Memory. That description misses some of the actual game mechanics, as it relies rather heavily upon a six-sided die. This die has six different colors on it, rather than the standard dots-for-number scheme, and it indicates which card you’re supposed to draw from the spread of cards whose faces are hidden and only colored dots are visible. Again, for the sake of this post, the key is the requirement that one has the six-sided colored die.
We did not.
Instead, we made do with a set of Candyland cards, which, conveniently use the same color set. However, as we played the game more frequently, the process of getting a three and then four-year-old to draw a card at random grew tiresome. Soon, my engineering brain began to tick and I started to code a solution. Sure, it’s crude. Sure, it uses Processing. Nevertheless, the does the job and it runs on the NES DVR, showing up on the big television screen.
If you find yourself in the same situation–needing a random six-colored digital die–here’s the source code I used in Processing: (note: the program runs full screen & the code isn’t perfectly clean but it should run just fine although you might need to comment out the font choice or the counter entirely. )
//The idea behind this program is to provide a digital replacement
//for the die that belongs to the kid’s Big Bad Wolf game.
//It’s a typical six-sided die with each side a different color:
//Red, Yellow, Green, Orange, Blue & Violet.color value = color(0);
int counter = 0;
int rotAngle = 0;
int angleChange = 2;void setup()
{
//size(400,400);
size(screen.width,screen.height);
fill(0);
PFont font;
font = loadFont(“HelveticaNeue-48.vlw”);
textFont(font);
}void draw()
{background(value);
if(counter == 0)
{
drawDieFaces(6);
}// if(counter > 0)
// {
// drawDieFaces(6);
// }
//Output a small counter to track the number of rollstext(counter,0,height – 50);
}
void keyPressed()
{for (int ii = 0; ii < 5; ii++)
{
value = colorVal( int(random(6)) );
}//For tracking purposes
counter++;
println(counter);}
void mouseClicked()
{
for (int ii = 0; ii < 5; ii++)
{
value = colorVal( int(random(6)) );
}//For tracking purposes
counter++;
println(counter);}
//Draws a single die face of the color specified
void dieSquare( int cx, int cy, int colorCode )
{
rectMode(CENTER);
noStroke();
fill(colorVal(colorCode));
rect(cx,cy,40,40);
}void drawDieFaces( int toDraw )
{
for (int i = 0; i <= toDraw; i++)
{
if(i <= 2)
dieSquare((i*width/3 + width/6),(height/4),i);
if(i > 2)
dieSquare(((i-3)*width/3 + width/6),(height/2 + height/4),i);
}
}//This is a specific function for this program. The colorCode
//parameter is 0=Red, 1=Orange , 2=Yellow, 3=Green, 4=Blue, 5= Violet
color colorVal(int cval)
{
color colorCode = 0;switch(cval)
{
case 0:
colorCode = color(255,0,0);
break;case 1:
colorCode = color(255,170,0);
break;case 2:
colorCode = color(255,255,0);
break;case 3:
colorCode = color(0,255,0);
break;case 4:
colorCode = color(0,0,255);
break;case 5:
colorCode = color(229,3,255);
break;
}
return colorCode;
}












