xxxxxxxxxx
59
/*
Source Photo Booth Draft 5 - pixelate video to canvas
by enickles
https://editor.p5js.org/enickles/sketches/HJ-43zqvf
source photo https://pixabay.com/photos/sea-cliff-hiker-c%c3%ades-islands-coast-6580562/
*/
let camera;
let img ;
let videoScale = 16; // 16
function preload() {
// preload() runs once
img = loadImage('sea.jpg');
}
function setup() {
pixelDensity(1);
createCanvas(640, 480);
camera = createCapture(VIDEO);
camera.size(width / videoScale, height / videoScale);
// camera.hide();
}
function draw() {
background(80);
image( img, 0, 100, width, 0.5 *height) ;
camera.loadPixels()
loadPixels();
for (let y = 0; y < camera.height; y++) {
for (let x = 0; x < camera.width; x++) {
let index = (x + y * camera.width) * 4;
let r = camera.pixels[index + 0];
let g = camera.pixels[index + 1];
let b = camera.pixels[index + 2];
// pixels[index+0] = b;
// pixels[index+1] = r;
// pixels[index+2] = g;
// pixels[index+3] = 255;
let a = 200 ;
let s = 100 ;
if ((b > s) && (r > s) && (g > s)) {
a = 0 ;
}
noStroke();
fill(r, g, b, a);
rect(x * videoScale, y * videoScale, videoScale, videoScale);
}
}
//updatePixels();
// displays camera
//image(camera, 0,0, 320, 240);
}