xxxxxxxxxx
53
let canvas;
let video;
function setup() {
canvas = createCanvas(800, 600);
video = createCapture(VIDEO,{flipped:true});
video.size(width, height);
video.hide();
}
function draw() {
image(video, 0, 0, width, height);
video.loadPixels();
for (x = 0; x < video.width; x += 10){
for (y = 0; y < video.height; y += 10){
let i = (y * video.width + x)*4;
let r = video.pixels[i];
let g = video.pixels[i + 1];
let b = video.pixels[i + 2];
let a = video.pixels[i + 3];
let brightValue = brightness(g); //tried r and b, liked this best; how to counteract flickering?
if (brightValue >= 50){
fill (250);
}else if (brightValue < 50){
fill(0);
}
rect(x, y, 20, 20);
}
}
keyPress();
}
function keyPress() {
if (keyIsPressed){
if (keyCode === ENTER); {
saveCanvas('you.png');
}
}
}