xxxxxxxxxx
86
let capture = null;
let sx = null; // source x
let sy = null; // soruce y
let sw = 20; // source width
let sh = 20; // source height
let dx = null; // destination x
let dy = null; // destination y
let dw = sw; //100; // destination width
let dh = sh; //100; // destination height
let cg = null;
function setup() {
createCanvas(500, 500);
capture = createCapture(VIDEO);
capture.hide();
// frameRate(60);
cg = createGraphics(width, height);
}
function draw() {
// background(220);
capture.loadPixels();
for( let i = 0; i < 30; i++ ){
let xPos = random(capture.width);
let yPos = random(capture.height);
let c = capture.get(xPos,yPos); // x,y of pixel
/*
cg.fill(c);
cg.noStroke();
cg.ellipse(xPos,yPos,10);
*/
fill(c);
noStroke();
ellipse(xPos,yPos,10);
}
// image(cg, 0, 0, width, height);
// capture.updatePixels();
/*
noStroke();
for( let i = 0; i < width/dw; i++){
for( let j = 0; j < height/dh; j++){
dx = dw * i;
dy = dh * j;
sx = sw * i;
sy = sh * j;
let c = capture.get(sx,sy); // x,y of pixel
fill(c);
rect(dx,dy,dw,dh);
}
}
*/
// Load in different layer
// cg.copy(capture, sx, sy, sw, sh, dx, dy, dw, dh);
// image(capture, 0, 0, width, height);
// image(cg, 0, 0, width, height);
/*
// Pixelated but super inefficient
for( let i = 0; i < width/dw; i++){
for( let j = 0; j < height/dh; j++){
dx = dw * i;
dy = dh * j;
sx = sw * i;
sy = sh * j;
let offset = 120;
copy(capture, sx, sy, sw, sh, dx, dy, dw-offset, dh-offset);
}
}
*/
}