Why is the video in canvas not working p5js?

edited May 2017 in Questions about Code

I was watching this video: 10.4 Brightness Mirror - p5.js Tutorial

and I am not getting my code to work:


var video;

function setup() {
  createCanvas(320, 240);
  pixelDensity(1);
  video = createCapture(VIDEO).size(320, 240);
}

function draw() {
  background(51);

  video.loadPixels();

  //pixels from canvas
  loadPixels();
  for (var y = 0; y < height; y++) {
    for (var x = 0; x < width; x++) {
      var index = (x + y * width)*4;
      pixels[index+0] = video.pixels[index+0];
      pixels[index+1] = video.pixels[index+1];
      pixels[index+2] = video.pixels[index+2];
      pixels[index+3] = 255;      
    }
  }
  updatePixels();
}

It shows like a ghost-like video :/ http://xxnotmuchxx.tumblr.com/post/160811589716

Sign In or Register to comment.