Last active
December 28, 2015 16:18
-
-
Save becojo/7527674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PImage img; | |
String filename = "chisas.jpg"; | |
void setup() { | |
img = loadImage(filename); | |
size(img.width, img.height); | |
noLoop(); | |
} | |
void draw() { | |
image(img, 0, 0); | |
loadPixels(); | |
int i; | |
for(i = 0; i < 8; i++) { | |
sortCols(); | |
sortRows(); | |
shiftLeft(1); | |
} | |
updatePixels(); | |
// saveFrame(filename + "-" + second() + "-" + millis() + ".png"); | |
} | |
void sortRows() { | |
int i; | |
for(i = 0; i < height; i++) { | |
sortRow(i, 0, width); | |
} | |
} | |
void sortCols() { | |
int i; | |
for(i = 0; i < width; i++) { | |
sortCol(i, 0, height); | |
} | |
} | |
void shiftLeft(int shift) { | |
int i; | |
for(i = 0; i < pixels.length; i++) { | |
pixels[i] = pixels[i] << shift; | |
} | |
} | |
void shiftRight(int shift) { | |
int i; | |
for(i = 0; i < pixels.length; i++) { | |
pixels[i] = pixels[i] >> shift; | |
} | |
} | |
void sortRow(int y, int from, int to) { | |
int length = to - from; | |
int[] unsorted = new int[length]; | |
int[] sorted; | |
int i; | |
for(i = 0; i < length; i++) { | |
unsorted[i] = pixels[from + i + y * width]; | |
} | |
sorted = sort(unsorted); | |
for(i = 0; i < length; i++) { | |
pixels[from + i + y * width] = sorted[i]; | |
} | |
} | |
void sortCol(int x, int from, int to) { | |
int length = to - from; | |
int[] unsorted = new int[length]; | |
int[] sorted; | |
int i; | |
for(i = 0; i < length; i++) { | |
unsorted[i] = pixels[(from + i) * width + x]; | |
} | |
sorted = sort(unsorted); | |
for(i = 0; i < length; i++) { | |
pixels[(from + i) * width + x] = sorted[i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment