Rasterizing Image with grid of dice

Hello @asymmetric,

Topic continued from here:

Here is an example of scaling a die:

// Scaling
// GLV
// 2022-12-15
// Topic:
// https://discourse.processing.org/t/rasterizing-image-with-grid-of-dice/40176

PImage img;
Die die;

void setup()
  {
  size(500,500);
  die = new Die();
  }

void draw()
  {
  background(255);
  
  int s = int(map(mouseX, 0, width, 0, 7)); // 1-6 dice sides
  float sc = map(mouseY, 0, height, 1, 10); // 1 to 9 die size
  
  push();
  translate(mouseX, mouseY);
  scale(sc, sc);
  die.show(0, 0, s); 
  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);
    }
  }
}

Scrutinize the changes that I made to your code.

You should be able to integrate the concepts with your code once you understand it.

Image used:
img = loadImage("http://learningprocessing.com/code/assets/sunflower.jpg");

References:

:)

2 Likes