Skip to content

Commit 3024474

Browse files
committed
finished w/o filters
1 parent 95047a8 commit 3024474

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

19 - Webcam Fun/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="photobooth">
1111
<div class="controls">
1212
<button onClick="takePhoto()">Take Photo</button>
13-
<!-- <div class="rgb">
13+
<div class="rgb">
1414
<label for="rmin">Red Min:</label>
1515
<input type="range" min=0 max=255 name="rmin">
1616
<label for="rmax">Red Max:</label>
@@ -29,7 +29,7 @@
2929
<input type="range" min=0 max=255 name="bmin">
3030
<label for="bmax">Blue Max:</label>
3131
<input type="range" min=0 max=255 name="bmax">
32-
</div> -->
32+
</div>
3333
</div>
3434

3535
<canvas class="photo"></canvas>

19 - Webcam Fun/scripts.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,48 @@ const canvas = document.querySelector('.photo');
33
const ctx = canvas.getContext('2d');
44
const strip = document.querySelector('.strip');
55
const snap = document.querySelector('.snap');
6+
7+
8+
function getVideo() {
9+
navigator.mediaDevices.getUserMedia({
10+
video: true,
11+
audio: false
12+
})
13+
.then(localmediastream => {
14+
console.log(localmediastream);
15+
video.src = window.URL.createObjectURL(localmediastream);
16+
video.play();
17+
})
18+
.catch(err => console.error(err));
19+
}
20+
21+
22+
function paintToCanvas() {
23+
const width = video.videoWidth;
24+
const height = video.videoHeight;
25+
canvas.width = width;
26+
canvas.height = height;
27+
28+
return setInterval(() => {
29+
ctx.drawImage(video, 0, 0, width, height);
30+
let pixels = ctx.getImageData(0, 0, width, height);
31+
console.log(pixels);
32+
debugger;
33+
}, 16);
34+
}
35+
36+
function takePhoto() {
37+
snap.currentTime = 0;
38+
snap.play();
39+
const data = canvas.toDataURL('image/jpeg');
40+
41+
const link = document.createElement('a');
42+
link.href = data;
43+
link.setAttribute('download', 'handsome');
44+
link.innerHTML = `<img src="${data}" alt="person"/>`;
45+
strip.insertBefore(link, strip.firstChild);
46+
47+
}
48+
49+
getVideo();
50+
video.addEventListener('canplay', paintToCanvas);

0 commit comments

Comments
 (0)