Where do I insert the following code?
This is what I have so far, but should I remove the random function from the class since the dots are referring to the brightness?
PImage img;
void setup(){
size(700,700);
img = loadImage("IMG_7741.jpeg");
img.resize(800,800);
}
void draw(){
background(#f1f1f1);
//noSrtoke();
float tilesX = 80;
float tilesY = tilesX;
float tileW = width / tilesX;
float tileH = height/ tilesY;
for (int x = 0; x < tilesX; x++){
for (int y = 0; y < tilesY; y++){
int px = int(x);
int py = int(y);
color c = img.get(px,py);
fill(c);
float b = brightness(c);
float s = map(b, 0, 255, 1, 6); // 1-6 dice sides
Die die = new Die(x*tileW, y*tileH );
die.show(s);
//rect(x*tileW, y*tileH, tilesX, tilesY);
}
}
}
class Die
{
//variable declarations here
int dots;
int myX;
int myY;
Die(float x, float y) //constructor
{
roll();
myX = x;
myY= y;
}
void roll()
{
if (s(6) <= 1)
{
dots = 1;
} else if (random(6) <= 2) // remove random?
{
dots = 2;
} else if (random(6) <= 3) // remove random?
{
dots = 3;
} else if (random(6) <= 4) // remove random?
{
dots = 4;
} else if (random(6) <= 5) // remove random?
{
dots = 5;
} else if (random(6) <= 6) // remove random?
{
dots = 6;
}
}
void show(int s )
{
fill(255,255,255);
rect(myX, myY, 50, 50);
fill(0, 0, 0);
if (dots == 1)
{
ellipse(myX+25, myY+25, 10, 10);
} else if (dots == 2)
{
ellipse(myX+10, myY+40, 10, 10);
ellipse(myX+40, myY+10, 10, 10);
} else if (dots == 3)
{
ellipse(myX+10, myY+40, 10, 10);
ellipse(myX+25, myY+25, 10, 10);
ellipse(myX+40, myY+10, 10, 10);
} else if (dots == 4)
{
ellipse(myX+10, myY+40, 10, 10);
ellipse(myX+10, myY+10, 10, 10);
ellipse(myX+40, myY+40, 10, 10);
ellipse(myX+40, myY+10, 10, 10);
} else if (dots == 5)
{
ellipse(myX+10, myY+40, 10, 10);
ellipse(myX+10, myY+10, 10, 10);
ellipse(myX+40, myY+40, 10, 10);
ellipse(myX+40, myY+10, 10, 10);
ellipse(myX+25, myY+25, 10, 10);
} else if (dots == 6)
{
ellipse(myX+10, myY+40, 10, 10);
ellipse(myX+10, myY+25, 10, 10);
ellipse(myX+10, myY+10, 10, 10);
ellipse(myX+40, myY+10, 10, 10);
ellipse(myX+40, myY+25, 10, 10);
ellipse(myX+40, myY+40, 10, 10);
}
}
}