Hi! I am trying to rasterize an image with dice connected to each pixel value, but I am running into a wall with sizing the dice appropriately.
Goal:
Current output:
Input image:
Current code:
PImage img;
void setup(){
size(800,800);
img = loadImage("IMG_7741.jpeg");
img.resize(80,80);
}
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 = int(map(b, 0, 255, 0, 7)); // 1-6 dice sides
Die die = new Die(x*tileW, y*tileH );
float sc = tileW/50; //50 is size of die face
push();
//scale(sc, sc);
die.show(x * tileW, y * tileH, int (s)); //Class
pop();
}
}
}
class Die
{
//variable declarations here
int dots;
float myX;
float myY;
Die(float x, float y) //constructor
{
float myX = x;
float myY= y;
}
void show(float myX, float myY, int s )
{
fill(255,255,255);
rect(myX, myY, 50, 50);
fill(0, 0, 0);
dots = s;
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);
}
}
}