videoLoop code


import processing.video.*;

// make videoLoop an object xxx
// use ArrayList
// or use fixed array
// use kinect camera?
// use thing in the hallway to test?
// timing & performance vs. ghost thing



float timer = 0;

VideoLoop loop1;

Capture video;
void setup() {
  size(640, 480);
  frameRate(30);
  background(0);

  println(Capture.list());

  loop1 = new VideoLoop();

  video = new Capture(this, 640, 480);
  video.start();
}

void captureEvent(Capture video) {
  //println("NEW FRAME!");
  video.read();
}

void draw() {

  pushMatrix();
  scale(-1,1);
  image(video, -video.width,0);
  popMatrix();

  
  if (loop1.playing == true) {
    loop1.play();
  } 
  else {
    loop1.record();

    noStroke();
    fill(0);
    rect(video.width, 0, video.width, height);
  }

  print(loop1.record);  
  print("   ");
  println(loop1.play);


  if (millis() - timer > 2500) {
    println(millis() - timer);
    timer = millis();
    loop1.play = 0;

    if (loop1.playing == true) {
      loop1.playing = false;
      loop1.record = 0;
    } 
    else {
      loop1.playing = true;
    }
  }
  
  
  fill(0);
  text(""+(int)frameRate,10,50);
}



class VideoLoop {

  PImage[] videoLoop;
  int record = 0;
  int play = 0;
  boolean playing = false;

  PImage oneFrame;
  float thresholder = 200;

  VideoLoop () {
    videoLoop = new PImage[0];
  }

  void record() {
    videoLoop = (PImage[]) expand(videoLoop, record+1); // expand function very inneficient
    videoLoop[record] = new PImage();
    videoLoop[record] = createImage(video.width, video.height, ARGB);
    videoLoop[record].loadPixels();

    //image(video, 0, 0);

    for (int x = 0; x<video.width; x++) {
      for (int y = 0; y thresholder) {
          //if so display the foreground color
          videoLoop[record].pixels[loc] = color(0, 0, 0, 0);
        } 
        else {
          //if not display green
          videoLoop[record].pixels[loc] = color(red(fgColor), green(fgColor), blue(fgColor), 250);
        }
      }
    }
    videoLoop[record].updatePixels();
    //image(videoLoop[record], videoLoop[record].width, 0);
    record++;
  }

  void play() {
    play++;

    if (play < record) {
      //pushMatrix();
      //scale(-1, 1);
      //image(videoLoop[play], -video.width, 0);

      //image(video, -video.width,0);
      //popMatrix();
      image(videoLoop[play], 0, 0);
    }
    //  noStroke();
    //  fill(255, 0, 0);
    //  rect(video.width, 0, video.width, height);
  }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s