Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Created November 5, 2017 15:56
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 KrabCode/4b6f699b70daacc8943a72b5447bf916 to your computer and use it in GitHub Desktop.
Save KrabCode/4b6f699b70daacc8943a72b5447bf916 to your computer and use it in GitHub Desktop.
Wave-pixelsorts a picture, records a handy dandy .mp4
import com.hamoid.VideoExport;
import processing.core.PApplet;
import processing.core.PImage;
import java.util.Arrays;
public class MainApp extends PApplet{
public static void main(String[] args)
{
PApplet.main("MainApp", args);
}
PImage backup, img;
VideoExport vx;
boolean rec;
public void settings()
{
backup = loadImage("C:\\PerlinDistort\\1.jpg");
backup.resize(backup.width, backup.height-1);
size(backup.width, backup.height);
}
public void setup(){
vx = new VideoExport(this);
vx.setFrameRate(60);
vx.startMovie();
rec = true;
}
public void draw()
{
//make a fresh working copy
try {
img = (PImage) backup.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
img = distort(img);
image(img, 0, 0, width, height);
//record video
if(rec){
vx.saveFrame();
}else{
vx.endMovie();
}
}
boolean up = true;
int intensity = 1;
private PImage distort(PImage img) {
img = fancySortImage(img,
intensity,
up);
if(up){
intensity++;
}else{
intensity--;
}
if(intensity > width){
up = false;
rec = false;
}
if(key == 'f'){
rec = false;
}
return img;
}
private PImage fancySortImage(PImage img, int cutoff, boolean up) {
//sort down
for(int y = 0; y < img.height; y++){
sortLine(img, cutoff, up, y);
}
return img;
}
private void sortLine(PImage img, int cutoff, boolean up, int y) {
int[] pixs = new int[cutoff];
if(up){
for(int x = 0; x < cutoff; x++){
pixs[x] = img.get(x, y);
}
Arrays.sort(pixs);
for(int x = 0; x < cutoff; x++){
img.set(x, y, pixs[x]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment