xxxxxxxxxx
76
/*
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/
Source photo Vassily Kandinsky, Gelb-Rot-Blau (Jaune-rouge-bleu), 1925
https://www.flickr.com/photos/8989278@N03/29827154098
*/
let camera;
let img ;
let videoScale = 16; // 16
function preload() {
// preload() runs once
img = loadImage('Kandinsky-jrb.jpg');
}
function setup() {
pixelDensity(1);
frameRate(20) ;
createCanvas(640, 480);
camera = createCapture(VIDEO);
camera.size(width / videoScale, height / videoScale);
// camera.hide();
if ( img.width > img.height ) {
img.resize( width, img.height*width/img.width );
} else {
img.resize(img.width*height/img.height, height);
}
}
function draw() {
background(80);
image( img, 0, 0, img.width, img.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 seuil = 100 ;
if ((b > seuil) && (r > seuil) && (g > seuil)) {
a = 0 ;
}
noStroke();
fill(r, g, b, a);
rect(x * videoScale, y * videoScale, videoScale, videoScale);
}
}
//updatePixels();
// displays camera
//image(camera, 0,0, 320, 240);
}