Skip to content

Instantly share code, notes, and snippets.

@bgola bgola/order.pde
Last active Jul 19, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.