xxxxxxxxxx
let cam, capture, fg
let off = -1
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
capture = createCapture(VIDEO)
capture.hide()
cam = createFramebuffer()
fg = createFramebuffer()
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight)
}
function mouseClicked() {
off = frameCount
fg.draw(() => clear())
}
function draw() {
cam.draw(() => {
imageMode(CENTER)
scale(-1, 1)
image(capture, 0, 0, width, height, 0, 0, capture.width, capture.height, COVER)
})
if (off > 0) {
fg.draw(() => {
const x = (frameCount - off) * 4
image(cam, -width/2+x, -height/2, 4, height, x, 0, 4, height)
})
}
push()
imageMode(CENTER)
image(cam, 0, 0)
image(fg, 0, 0)
pop()
}