-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.js
48 lines (34 loc) · 1007 Bytes
/
controls.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
const arrSize = 32
let vals = new Array(32)
function fillArray() {
for (let i = 0; i < arrSize; i++) {
vals[i] = (Math.random()*100)
}
}
fillArray()
const selector = document.getElementById('sort-selector')
selector.onclick = () => {
let desc = document.getElementById('info-box')
desc.innerHTML = sortDescriptions[selector.selectedIndex]
}
selector.onclick()
const randomize = document.getElementById('randomize-btn')
randomize.onclick = () => {
fillArray()
highlight()
activeSort = null
}
const sortBtn = document.getElementById('start-sort-btn')
sortBtn.onclick = () => {
activeSort = doSort(vals, selector.selectedIndex)
}
const pauseBtn = document.getElementById('pause-btn')
pauseBtn.onclick = () => {
activeSort = null
}
const slider = document.getElementById('speed-slider')
slider.onchange = () => {
let interval = (101 - slider.value) * 2
clearInterval(visArea.interval)
visArea.interval = setInterval(updateCanvas, interval)
}