Creating a grid of dice representing an image

This belongs in the show function, no?

I removed the following variable from the constructor…

I’m now recieving the same error message for the same variable in the show function now.

void show(float myX, float myY, float dots )
  {
    fill(255,255,255);
    dots = s;
    rect(myX, myY, 50, 50);
    fill(0, 0, 0);

void show(float myX, float myY, int s )

      die.show(x * tileW, y * tileH, s); //Class

“The method show(float,float,int) in the type image_rasterization. Die is not applicable for the arguments (float,float,float).”

  • List item

The function “show()” expects parametesrs like "show(float,float,int)
The value of the local variable “myX” is not used.
The value of the local variable “myY” is not used.

Do you still have a line like this in draw()?

What about

int s = int(map(…

And then like above?

1 Like

I am still receiving the same errors.

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
      //println(sc, 1/sc);

      push();
      scale(sc, sc);
      //int s = int(random(0, 7));  // This will give 0 to 6! Use print() to see this before and after int()
      die.show(x * tileW, y * tileH, s); //Class
      pop();

It worked but the compiler still has the following errros

The value of the local variable “myX” is not used.
The value of the local variable “myY” is not used.

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
      //println(sc, 1/sc);

      push();
      scale(sc, sc);
      //int s = int(random(0, 7));  // This will give 0 to 6! Use print() to see this before and after int()
      die.show(x * tileW, y * tileH, int (s)); //Class
      pop();
      }

Just a warning. Ignore it.

Does it look cool?

Do you realize that you only analyze the 80 x 80 pixels at the top of your image?

Blockquote

Yes, lol! How do I change this?

1 Like

Doesn’t look good…

check the numbers…

As I said: 80x80…

Maybe resize your image to 80x80 too?

But the dices should fill the entire window

Now you can work with it!

Really try to understand the code and improve it!!

Congratulations!!!

The for loop has the numbers that are used to analyze the image ; using get. Change the for loop.

Really try to understand everything

Guessing won’t help you in the long run

The for loop has the numbers that are used to analyze the image ; using get. Change the for loop.

How should I change the for loop?

1 Like


LOL

Do you understand the principle what we are doing?

The image has a size set by resize in setup.

The for loop loops over each pixel, it therefore must have same upper boundary as width and height of image.

Then we enlarge the image using dice. Here
we say +tileW and * tileH. The resulting grid of dices should not exceed your window / screen?

1 Like

The dice are now fitting within the window screen, but the dice do not reflect the pixel value.

Post your entire code every time

Do the 2 for loops cover the entire image now??

Why does the map statement not result in 1…6 but in 0…7???

But good progress here! We see something!!!

1 Like
PImage img;

void setup(){
  size(800,800);
  img = loadImage("IMG_7741.jpeg");
  img.resize(800,800);
}

void draw(){
  background(#f1f1f1);
  //noSrtoke();
  
  float tilesX = 15;
  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);
    }
  }
}

???

The image is 800 and the for loop goes up to 15…
Bad

Probably you also want smaller dices!!!

1 Like