//Creating and Initializing variables
PImage pic;
int horizontal=50;
int vertical=40;
int cuts= horizontal * vertical;
PImage [] jigsaw = new PImage[cuts];
int cutX;
int cutY;
void setup() {
size(500, 400);
//webimage
String link="https://c1.staticflickr.com/1/695/22845688014_54ee4fad33_k.jpg";
pic = loadImage(link, "jpg");
image (pic, 0, 0, width, height);
//slices size
cutX= width / horizontal;
cutY= height / vertical;
//taking the cuts
for (int i=0; i<cuts; i++) {
int x= (i % horizontal) * cutX;
int y= (i / vertical) * cutY;
// fill the array
jigsaw [i] = get (x, y, cutX, cutY);
}
noLoop();
}
void draw() {
//background(0);
//New cordinates for the pices
for (int i=0; i<cuts; i++) {
int x= (i % horizontal) * cutX;
int y= (i / vertical) * cutY;
//random interger
int puzzle = int(random(cuts));
//puzzle= puzzle % cuts;
//create the jigsaw
image(jigsaw[puzzle], x, y);
}
}