Processing v3.0.0 Quellcode:
// number of max slices
int maxSlices = 256;
Slice[] slice = new Slice[maxSlices];
// number of start slices
int n = 16;
float step = 2;
PImage img;
void setup() {
smooth();
// background colour
background(0);
// load Image
img = loadImage("https://c1.staticflickr.com/1/722/23771752525_984f6d44d7_c.jpg");
// window size
size(720,405);
for (int i = 0; i < n; i++) {
slice[i] = new Slice(int(i*img.width/n),int(img.width/n),img);
}
println(width);
println(height);
}
void draw() {
// background colour
fill(0);
// create rectangle with width and height of the image
rect(0,0,width,height);
for (int i = 0; i < n; i++) {
slice[i].paint();
}
}
void mousePressed() {
save("pic.jpg");
n = int(n*step);
if(n > maxSlices | n < 4){
step = 1/step;
n = int(n*step*step);
}
for (int i = 0; i < n; i++) {
slice[i] = new Slice(int(i*img.width/n),int(img.width/n),img);
}
}
class Slice {
int xini;
int xSize;
PImage img;
PImage imgSlice;
float vel;
float xVel;
float xPos;
float sign;
float seed;
float iter = 0;
float t = 100;
Slice(int xiniTemp, int xSizeTemp, PImage imgTemp) {
xini = xiniTemp;
xSize = xSizeTemp;
img = imgTemp;
imgSlice = createImage(xSize,img.height,ARGB);
vel = 0;
xVel = 0;
sign = random(-1,1);
sign = sign/abs(sign);
seed = random(0,100);
xPos = 0.5*(width-img.width) + xini + xVel + sign*noise(seed)*img.width/3;
int p = 0;
for (int i = 0; i < img.height; i++) {
for (int j = 0; j < img.width; j++) {
if((j >= xini) & (j < xini + xSize)){
imgSlice.pixels[p] = img.pixels[j + i*img.width];
p +=1;
}
}
}
}
// create sliced image
void paint() {
image(imgSlice,xPos,0);
}
}