Created
September 6, 2016 16:41
-
-
Save bgola/cd152378c211959eb3b960851b1b4cc5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.Map; | |
PImage img; | |
int sf=0; | |
float frame = 0; | |
void setup() { | |
size(851, 315); | |
img = loadImage("path"); | |
img.resize(width, height); | |
} | |
void draw() { | |
background(0); | |
loadPixels(); | |
float[] columns = new float[width]; | |
float[] columns_sorted = new float[width]; | |
HashMap<Float,Integer> hm = new HashMap<Float,Integer>(); | |
float n = 0; | |
for(int i=0; i<width; i++) { | |
float total=0; | |
for (int j=0; j<height; j++) { | |
color c = img.get(i, j); | |
total += brightness(c); | |
} | |
float mean = total / height; | |
columns[i] = mean; | |
hm.put(mean, i); | |
} | |
columns_sorted = sort(columns); | |
for (int c=0; c<width; c++) { | |
int column = hm.get(columns_sorted[width-c-1]); | |
for (int l=0; l<height; l++) { | |
n+=0; | |
int pixel = (int)(width*l+c) ;// + (map(noise(n), 0, 1, -10, 10))); | |
if (pixel < 0) pixel = 0; | |
if (pixel > (width-1)*(height-1)) pixel = (width-1)*(height-1); | |
//pixels[pixel] = color(brightness(img.get(line, x))); | |
pixels[pixel] = img.get(column, l); | |
} | |
} | |
updatePixels(); | |
} | |
void keyPressed() { | |
if (key == 's') { | |
save("frame.jpg"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment