Skip to content

Instantly share code, notes, and snippets.

@catarak
Created April 22, 2017 12:56
Show Gist options
  • Save catarak/a721b7a3b67dbb726315bc0529843f06 to your computer and use it in GitHub Desktop.
Save catarak/a721b7a3b67dbb726315bc0529843f06 to your computer and use it in GitHub Desktop.
var capture;
var stepSize = 5;
function setup() {
createCanvas(400, 300);
capture = createCapture(VIDEO);
capture.size(400, 300);
capture.hide();
rectMode(CENTER);
noStroke();
}
function draw() {
background(50);
fill(255);
capture.loadPixels();
for (var cy = 0; cy < capture.height; cy += stepSize) {
for (var cx = 0; cx < capture.width; cx += stepSize) {
var offset = ((cy*capture.width)+cx)*4;
var xpos = (cx / capture.width) * width;
var ypos = (cy / capture.height) * height;
var pixelBrightness = capture.pixels[offset+1]/255; //TECHNICALLY the green brightness
rect(width - xpos, ypos, stepSize, stepSize*pixelBrightness);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment