We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys, I downloaded Processing some days ago in order to pixelsort some images. I don't know Java, but I know quiet well other programming languages, so I searched on the Internet for some useful infos and I find out that there is a function that basically saves the images. I have this program (downloaded from the Internet), but I don't know where to put the saveFrame part (also because I didn't write the program and I don't really know how it work, apart a few sections of it). Can you help me, please? Here is the program, thank you soooo much to everyone who will answer :)
int mode = 1;
//MODE: //0 -> black //1 -> bright //2 -> white //b(16777216)
PImage img; String imgFileName = "tumblr_o4e432d6cp1u8wonlo1_1280.jpg"; String fileType = "png";
int loops = 1;
int blackValue = -16000000; int brigthnessValue = 60; int whiteValue = -13000000;
int row = 0; int column = 0;
boolean saved = true;
void setup() { size(400, 200); surface.setResizable(true); img = loadImage(imgFileName);
surface.setSize(img.width, img.height); image(img, 0, 0); }
void draw() { while(column < width-1) { img.loadPixels(); sortColumn(); column++; img.updatePixels(); }
while(row < height-1) { img.loadPixels(); sortRow(); row++; img.updatePixels(); }
image(img,0,0); if(!saved && frameCount >= loops) { save("DONE.jpg"); saved = true; println("DONE"+frameCount); System.exit(0); } }
void sortRow() { int x = 0; int y = row; int xend = 0;
while(xend < width-1) { switch(mode) { case 0: x = getFirstNotBlackX(x, y); xend = getNextBlackX(x, y); break; case 1: x = getFirstBrightX(x, y); xend = getNextDarkX(x, y); break; case 2: x = getFirstNotWhiteX(x, y); xend = getNextWhiteX(x, y); break; default: break; }
if(x < 0) break;
int sortLength = xend-x;
color[] unsorted = new color[sortLength];
color[] sorted = new color[sortLength];
for(int i=0; i<sortLength; i++) {
unsorted[i] = img.pixels[x + i + y * img.width];
}
sorted = sort(unsorted);
for(int i=0; i<sortLength; i++) {
img.pixels[x + i + y * img.width] = sorted[i];
}
x = xend+1;
} }
void sortColumn() { int x = column; int y = 0; int yend = 0;
while(yend < height-1) { switch(mode) { case 0: y = getFirstNotBlackY(x, y); yend = getNextBlackY(x, y); break; case 1: y = getFirstBrightY(x, y); yend = getNextDarkY(x, y); break; case 2: y = getFirstNotWhiteY(x, y); yend = getNextWhiteY(x, y); break; default: break; }
if(y < 0) break;
int sortLength = yend-y;
color[] unsorted = new color[sortLength];
color[] sorted = new color[sortLength];
for(int i=0; i<sortLength; i++) {
unsorted[i] = img.pixels[x + (y+i) * img.width];
}
sorted = sort(unsorted);
for(int i=0; i<sortLength; i++) {
img.pixels[x + (y+i) * img.width] = sorted[i];
}
y = yend+1;
} }
//BLACK int getFirstNotBlackX(int _x, int _y) { int x = _x; int y = _y; color c; while((c = img.pixels[x + y * img.width]) < blackValue) { x++; if(x >= width) return -1; } return x; }
int getNextBlackX(int _x, int _y) { int x = _x+1; int y = _y; color c; while((c = img.pixels[x + y * img.width]) > blackValue) { x++; if(x >= width) return width-1; } return x-1; }
//BRIGHTNESS int getFirstBrightX(int _x, int _y) { int x = _x; int y = _y; color c; while(brightness(c = img.pixels[x + y * img.width]) < brigthnessValue) { x++; if(x >= width) return -1; } return x; }
int getNextDarkX(int _x, int _y) { int x = _x+1; int y = _y; color c; while(brightness(c = img.pixels[x + y * img.width]) > brigthnessValue) { x++; if(x >= width) return width-1; } return x-1; }
//WHITE int getFirstNotWhiteX(int _x, int _y) { int x = _x; int y = _y; color c; while((c = img.pixels[x + y * img.width]) > whiteValue) { x++; if(x >= width) return -1; } return x; }
int getNextWhiteX(int _x, int _y) { int x = _x+1; int y = _y; color c; while((c = img.pixels[x + y * img.width]) < whiteValue) { x++; if(x >= width) return width-1; } return x-1; }
//BLACK int getFirstNotBlackY(int _x, int _y) { int x = _x; int y = _y; color c; if(y < height) { while((c = img.pixels[x + y * img.width]) < blackValue) { y++; if(y >= height) return -1; } } return y; }
int getNextBlackY(int _x, int _y) { int x = _x; int y = _y+1; color c; if(y < height) { while((c = img.pixels[x + y * img.width]) > blackValue) { y++; if(y >= height) return height-1; } } return y-1; }
//BRIGHTNESS int getFirstBrightY(int _x, int _y) { int x = _x; int y = _y; color c; if(y < height) { while(brightness(c = img.pixels[x + y * img.width]) < brigthnessValue) { y++; if(y >= height) return -1; } } return y; }
int getNextDarkY(int _x, int _y) { int x = _x; int y = _y+1; color c; if(y < height) { while(brightness(c = img.pixels[x + y * img.width]) > brigthnessValue) { y++; if(y >= height) return height-1; } } return y-1; }
//WHITE int getFirstNotWhiteY(int _x, int _y) { int x = _x; int y = _y; color c; if(y < height) { while((c = img.pixels[x + y * img.width]) > whiteValue) { y++; if(y >= height) return -1; } } return y; }
int getNextWhiteY(int _x, int _y) { int x = _x; int y = _y+1; color c; if(y < height) { while((c = img.pixels[x + y * img.width]) < whiteValue) { y++; if(y >= height) return height-1; } } return y-1; }
Answers
edit post, highlight code, press ctrl-o