Skip to content

Instantly share code, notes, and snippets.

@bgola
Last active July 19, 2016 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgola/e13e34e8bd71927a583f789931492d6b to your computer and use it in GitHub Desktop.
Save bgola/e13e34e8bd71927a583f789931492d6b to your computer and use it in GitHub Desktop.
import java.util.Map;
PImage img;
float line_size = 30;
float space = 20;
int sf=0;
float frame = 0;
void setup() {
size(700, 700);
img = loadImage("/home/bgola/fotos/me/mequadrado2.jpg");
img.resize(width, height);
}
void draw() {
background(0);
loadPixels();
float[] lines = new float[height];
float[] lines_sorted = new float[height];
HashMap<Float,Integer> hm = new HashMap<Float,Integer>();
float n = 0;
for(int i=0; i<height; i++) {
float total=0;
for (int j=0; j<width; j++) {
color c = img.get(i, j);
total += brightness(c);
}
float mean = total / width;
lines[i] = mean;
hm.put(mean, i);
}
lines_sorted = sort(lines);
for (int l=0; l<height; l++) {
int line = hm.get(lines_sorted[height-l-1]);
for (int x=0; x<width; x++) {
int pixel = width*x+l;
//pixels[pixel] = color(brightness(img.get(line, x)));
pixels[pixel] = img.get(line, x);
}
}
updatePixels();
}
void keyPressed() {
if (key == 's') {
save("me.jpg");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment