Skip to content

Instantly share code, notes, and snippets.

@johnniehard
Created November 6, 2014 13:43
Show Gist options
  • Save johnniehard/1639c2d8b3ad0f5d5bf4 to your computer and use it in GitHub Desktop.
Save johnniehard/1639c2d8b3ad0f5d5bf4 to your computer and use it in GitHub Desktop.
Take parts of an image and shuffle them around
//ta delar ur en bild och shuffla runt dem
int col = 4; //even numbers
int row = 2;
int w;
int h;
PImage img;
PImage[] delar = new PImage[col*row];
void setup() {
img = loadImage("image.jpg");
img.resize(600, 400); //even numbers
size(img.width, img.height);
w = img.width/col;
h = img.height/row;
int delCount = 0;
for (int x = 0; x < img.width; x+=w) {
for (int y = 0; y < img.height; y+=h) {
delar[delCount] = img.get(x, y, w, h);
if (delCount < delar.length-1) {
delCount++;
}
}
}
int counter = 0;
for (int x = 0; x < img.width; x+=w) {
for (int y = 0; y < img.height; y+=h) {
image(delar[int(random(delar.length))], x, y);
if (counter < delar.length-1) {
counter++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment