HW3: mastery check changes
This commit is contained in:
parent
15bb5f52e2
commit
767fc8cb77
1 changed files with 24 additions and 12 deletions
|
@ -56,11 +56,22 @@ class App {
|
||||||
|
|
||||||
const player = document.createElement('video');
|
const player = document.createElement('video');
|
||||||
player.addEventListener('loadeddata', () => {
|
player.addEventListener('loadeddata', () => {
|
||||||
|
player.play();
|
||||||
|
setTimeout(() => {
|
||||||
const imgCanvas = document.createElement('canvas');
|
const imgCanvas = document.createElement('canvas');
|
||||||
imgCanvas.width = this.canvas.width;
|
imgCanvas.width = this.canvas.width;
|
||||||
imgCanvas.height = this.canvas.height;
|
imgCanvas.height = this.canvas.height;
|
||||||
const imgCtx = imgCanvas.getContext('2d');
|
const imgCtx = imgCanvas.getContext('2d');
|
||||||
imgCtx.drawImage(player, 0, 0, canvas.width, canvas.height);
|
imgCtx.drawImage(player, 0, 0, canvas.width, canvas.height);
|
||||||
|
const imgData = imgCtx.getImageData(0, 0, imgCanvas.width,
|
||||||
|
imgCanvas.height);
|
||||||
|
|
||||||
|
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');
|
const img = document.createElement('img');
|
||||||
img.src = imgCanvas.toDataURL();
|
img.src = imgCanvas.toDataURL();
|
||||||
img.addEventListener('load', () => {
|
img.addEventListener('load', () => {
|
||||||
|
@ -69,6 +80,7 @@ class App {
|
||||||
});
|
});
|
||||||
|
|
||||||
player.srcObject.getVideoTracks().forEach(track => track.stop());
|
player.srcObject.getVideoTracks().forEach(track => track.stop());
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
|
|
Reference in a new issue