GMU:Processing im Park/Emilio Aguas/Code Pond Effect

From Medien Wiki
< GMU:Processing im Park‎ | Emilio Aguas
Revision as of 21:27, 25 January 2016 by EmilioAguas (talk | contribs) (Created page with "====--- Processing3.0 Code--- ==== <source lang="java"> import processing.video.*; Capture video; int signal = 0; ArrayList frames = new ArrayList(); void setup() { size(6...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

--- Processing3.0 Code---

import processing.video.*;

Capture video;
int signal = 0;
ArrayList frames = new ArrayList();

void setup() {
  size(640, 480);
  video = new Capture(this, width, height);
   video.start();  
}

void captureEvent(Capture camera) {
  camera.read();
  
  // Copy the current video frame into an image, so it can be stored in the buffer
  PImage img = createImage(width, height, RGB);
  video.loadPixels();
  arrayCopy(video.pixels, img.pixels);
  
  frames.add(img);
  
  // Once there are enough frames, remove the oldest one when adding a new one
  if (frames.size() > height/2) {
    frames.remove(0);
  }
}

void draw() {
 // Set the image counter to 0
 int currentImage = 0;
 
 loadPixels();
  
  // Begin a loop for displaying pixel rows of 4 pixels height
  for (int y = 0; y < video.height; y+=5) {
    // Go through the frame buffer and pick an image, starting with the oldest one
    if (currentImage < frames.size()) {
      PImage img = (PImage)frames.get(currentImage);
      
      if (img != null) {
        img.loadPixels();
        
        // Put 4 rows of pixels on the screen
        for (int x = 0; x < video.width; x++) {
          pixels[x + y * width] = img.pixels[x + y * video.width];
          pixels[x + (y + 1) * width] = img.pixels[x + (y + 1) * video.height];
          pixels[x + (y + 2) * width] = img.pixels[x + (y + 1) * video.width];
          pixels[x + (y + 3) * width] = img.pixels[x + (y + 1) * video.width];
          pixels[x + (y + 4) * width] = img.pixels[x + (y + 1) * video.height];
        }  
      }
      
      // Increase the image counter
      currentImage++;
       
    } else {
      break;
    }
  }
  
  updatePixels();
}