var video = document.createElement('video'); var canvas = document.getElementById('picture'); var ctx = canvas.getContext('2d'); // polyfill from https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement.toBlob if (!HTMLCanvasElement.prototype.toBlob) { Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { value: function (callback, type, quality) { var binStr = atob( this.toDataURL(type, quality).split(',')[1] ), len = binStr.length, arr = new Uint8Array(len); for (var i=0; i -1) { ctx.drawImage(snap, 0, 0, canvas.width, canvas.height); if((timestamp - flash) < (flashTime * 2)) { ctx.fillStyle = 'rgba(255,255,255,'+Math.min(1, 1 + (1 - (timestamp - flash)/flashTime))+')'; ctx.fillRect(0,0,canvas.width, canvas.height); } } else { ctx.fillStyle = 'black'; ctx.fillRect(0,0,canvas.width, canvas.height); ctx.fillStyle = 'white'; writeMessage(); ctx.save(); ctx.translate(canvas.width, 0); ctx.scale(-1, 1); ctx.drawImage(video, 0, 50, canvas.width, canvas.width * video.videoHeight / video.videoWidth ); ctx.restore(); if(bach_ready) { ctx.drawImage(bach, 0, 0, canvas.width, canvas.width * bach.height / bach.width); } } window.requestAnimationFrame(step); } window.requestAnimationFrame(step);