Skip to content

Instantly share code, notes, and snippets.

@mrmemmo
Created March 14, 2019 22:35
Show Gist options
  • Save mrmemmo/6ba02f14d25cf2632466d0c47c43d61b to your computer and use it in GitHub Desktop.
Save mrmemmo/6ba02f14d25cf2632466d0c47c43d61b to your computer and use it in GitHub Desktop.
import java.io.FilenameFilter;
int counter = 1;
int pn = 16;//number of puzzle pieces
PImage img; // Declare a variable of type PImage
PImage[][] pieceArray = new PImage[pn][pn];//array of images
int width = 800;
int height = 600;
void setup() {
frameRate(5);
size(800, 600);
loadNextImage();
}//end of setup
void draw() {
background(0);
image(pieceArray[0][0],width/pn, height/pn);
}
void loadNextImage(){
img = loadImage("images/" + counter + ".jpg");
img.resize(800, 600);
for (int i = 0; i < pn; i++) {
for (int j = 0; j < pn; j++) {
pieceArray[i][j] = img.get(i * width/pn, j * height/pn, width/pn, height/pn);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment