1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/********************************************************/
/* Erik Kastner. Processing fun - processing.org/download
/********************************************************/
import processing.video.*;

Capture video;
int vidSize;
int numBlocks;
int numColumns;

void setup() {
  size(640, 480, P3D);

  // also try with other video sizes
  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);  // try different frame rates for different effects
}


void draw() {
  // by using video.available, only the frame rate need be set inside setup()
  if (video.available()) {
    video.read();
    set(0, 0, video);
    
    loadPixels();
    for (int j=numBlocks-1; j > 0; j--) {
      //println("Copying from " + (j-1) + " to: " + 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);
  }
}