import processing.video.*;
Capture video;
int vidSize;
int numBlocks;
int numColumns;
void setup() {
size(640, 480, P3D);
video = new Capture(this, 64, 48);
numBlocks = (height * width) / (video.height * video.width);
numColumns = width / video.width;
vidSize = video.height * video.width - 1;
loadPixels();
for (int i = 0; i < width*height; i++) {
pixels[i] = #000000;
}
updatePixels();
background(0);
frameRate(10);
}
void draw() {
if (video.available()) {
video.read();
set(0, 0, video);
loadPixels();
for (int j=numBlocks-1; j > 0; j--) {
copyBlock(j-1, j);
}
updatePixels();
}
}
void copyBlock(int from, int to) {
int toX = to % numColumns;
int toY = to / numColumns;
int tOffset = (toX * video.width) + (toY * width * video.height);
int fromX = from % numColumns;
int fromY = from / numColumns;
int fOffset = (fromX * video.width) + (fromY * width * video.height);
for (int vOffset=0; vOffset<video.height; vOffset++) {
arraycopy(pixels, (vOffset * width) + fOffset, pixels, (vOffset * width) + tOffset, video.width - 1);
}
}