-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (51 loc) · 1.45 KB
/
script.js
File metadata and controls
55 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const canvasArea = document.querySelector(".canvas-area")
const canvas = document.querySelector("#canvas")
const ctx = canvas.getContext("2d", { willReadFrequently: true })
const imageCanvas = document.querySelector("#imageCanvas")
const imageCtx = imageCanvas.getContext("2d")
const video = document.createElement("video")
const resetButton = document.querySelector("#reset-button")
const downloadButton = document.querySelector("#download-button")
const $Effect = new TimeWarp({
lineWidth: 3,
lineColour: "#00FFFFFF",
speed: 1,
videoCanvas: canvas,
videoCtx: ctx,
video,
imageCanvas: imageCanvas,
imageCtx: imageCtx,
})
const $Devices = new Devices({
selectEl: document.getElementById("deviceList"),
constraints: {
video: {
facingMode: { ideal: "environment" },
codec: "h264",
},
},
getUserMediaSuccess: (stream) => {
canvasArea.classList.remove("blocked")
video.srcObject = stream
video.play()
video.addEventListener("loadedmetadata", () => {
canvas.width = video.videoWidth
canvas.height = video.videoHeight
imageCanvas.width = video.videoWidth
imageCanvas.height = video.videoHeight
$Effect.animate()
})
},
getUserMediaError: (error) => {
canvasArea.classList.add("blocked")
},
})
$Devices.onChange(() => {
$Effect.reset()
})
resetButton.addEventListener("click", () => {
$Effect.reset()
})
downloadButton.addEventListener("click", () => {
$Effect.download()
})