function setup() {
  createCanvas(800, 600);

  image(img);
  tileWidth = width / tileCountY;
  tileHeight = height / tileCountX;

  noCursor();
  noFill();
  stroke(255);
}
cutting and multiplying an area of the image

MOUSE
position x/y         : area position
left click           : multiply the area

KEYS
1-3                  : area size
r                    : toggle random area
s                    : save png