-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
98 lines (82 loc) · 2.47 KB
/
script.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @author Axel Boberg <[email protected]>
* @copyright Axel Boberg © 2021
* @license MIT
*/
const OUTPUT_LABELS = ['PVW', 'PGM']
const INPUT_ROWS = 2
const INPUT_LABELS = ['Webcam', 'Unsplash', 'Big Buck Bunny',,,,,'Black']
const INPUT_SOURCES = [
window.CanvasComponent.playableFactory.webcam(),
window.CanvasComponent.playableFactory.image('https://source.unsplash.com/random'),
window.CanvasComponent.playableFactory.video('./media/BigBuckBunny_trailer.webm'),
window.CanvasComponent.playableFactory.bars(),
window.CanvasComponent.playableFactory.bars(),
window.CanvasComponent.playableFactory.bars(),
window.CanvasComponent.playableFactory.bars(),
window.CanvasComponent.playableFactory.color('black')
]
const outputs = document.querySelector('.outputs')
const inputs = document.querySelector('.inputs')
const inputCanvases = []
const outputCanvases = []
/*
Setup outputs
*/
;(function () {
for (let i = 0; i < OUTPUT_LABELS.length; i++) {
const canvas = new window.CanvasComponent()
canvas.source = window.CanvasComponent.playableFactory.color('black')
outputCanvases[i] = canvas
const el = canvas.render()
el.dataset.label = OUTPUT_LABELS[i]
outputs.appendChild(el)
}
})()
/*
Setup inputs
*/
;(function () {
const rows = Array(INPUT_ROWS)
.fill(undefined)
.map(() => document.createElement('div'))
for (let i = 0; i < INPUT_SOURCES.length; i++) {
const canvas = new window.CanvasComponent()
canvas.source = INPUT_SOURCES[i]
inputCanvases[i] = canvas
const el = canvas.render()
el.addEventListener('click', () => {
outputCanvases[0].source = window.CanvasComponent.playableFactory.image(canvas.canvas)
})
el.dataset.label = INPUT_LABELS[i] || i + 1
const row = Math.floor(i / (INPUT_SOURCES.length / INPUT_ROWS))
rows[row].appendChild(el)
}
rows.forEach(row => {
inputs.appendChild(row)
})
})()
/*
Setup keyboard shortcuts
*/
;(function () {
window.addEventListener('keydown', e => {
/*
Set preview on digit
*/
if (e.code.includes('Digit')) {
const input = parseInt(e.key) - 1
if (!inputCanvases[input]) return
outputCanvases[0].source = window.CanvasComponent.playableFactory.image(inputCanvases[input].canvas)
return
}
/*
Cut on space
*/
if (e.code === 'Space') {
const tmp = outputCanvases[0].source
outputCanvases[0].source = outputCanvases[1].source
outputCanvases[1].source = tmp
}
})
})()