HW3: mastery check changes
This commit is contained in:
parent
15bb5f52e2
commit
767fc8cb77
1 changed files with 24 additions and 12 deletions
|
@ -56,19 +56,31 @@ class App {
|
||||||
|
|
||||||
const player = document.createElement('video');
|
const player = document.createElement('video');
|
||||||
player.addEventListener('loadeddata', () => {
|
player.addEventListener('loadeddata', () => {
|
||||||
const imgCanvas = document.createElement('canvas');
|
player.play();
|
||||||
imgCanvas.width = this.canvas.width;
|
setTimeout(() => {
|
||||||
imgCanvas.height = this.canvas.height;
|
const imgCanvas = document.createElement('canvas');
|
||||||
const imgCtx = imgCanvas.getContext('2d');
|
imgCanvas.width = this.canvas.width;
|
||||||
imgCtx.drawImage(player, 0, 0, canvas.width, canvas.height);
|
imgCanvas.height = this.canvas.height;
|
||||||
const img = document.createElement('img');
|
const imgCtx = imgCanvas.getContext('2d');
|
||||||
img.src = imgCanvas.toDataURL();
|
imgCtx.drawImage(player, 0, 0, canvas.width, canvas.height);
|
||||||
img.addEventListener('load', () => {
|
const imgData = imgCtx.getImageData(0, 0, imgCanvas.width,
|
||||||
this.background = img;
|
imgCanvas.height);
|
||||||
this.redrawAll();
|
|
||||||
});
|
|
||||||
|
|
||||||
player.srcObject.getVideoTracks().forEach(track => track.stop());
|
for (let i = 0; i < data.length; i += 4) {
|
||||||
|
const pixel = (data[i] + 2 * data[i+1] + data[i+2]) / 4;
|
||||||
|
data[i] = data[i+1] = data[i+2] = pixel;
|
||||||
|
}
|
||||||
|
imgCtx.putImageData(imgData, 0, 0);
|
||||||
|
|
||||||
|
const img = document.createElement('img');
|
||||||
|
img.src = imgCanvas.toDataURL();
|
||||||
|
img.addEventListener('load', () => {
|
||||||
|
this.background = img;
|
||||||
|
this.redrawAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
player.srcObject.getVideoTracks().forEach(track => track.stop());
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
|
|
Reference in a new issue