forked from tensorfire/cyborg-writer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
48 lines (38 loc) · 1.58 KB
/
util.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
async function loadArrayFromURL(fileName, opts){
var buffer = new Float32Array(await loadBuffer(fileName, opts))
var shape = fileName.match(/\d+(x\d+)*$/)[0].split('x').map(k => +k)
return ndarray(buffer, shape)
}
async function loadBuffer(fileName, {progressContainer}={}){
var xhr = new XMLHttpRequest()
xhr.open('GET', fileName, true)
xhr.responseType = 'arraybuffer'
xhr.send(null)
var prog = createProgress('downloading model', progressContainer)
xhr.onprogress = function(progress){
prog.value = progress.loaded / progress.total
}
await new Promise(resolve => xhr.onload = resolve)
prog.destroy()
return xhr.response;
}
function createProgress(label, container){
// document.querySelector('.pie-wrapper').style.display = ''
// document.querySelector('.pie-wrapper .label').innerText = label;
return {
set value(n){
// document.querySelector('.pie .left-side').style.transform = 'rotate(' + (360 * n) + 'deg)'
// document.querySelector('.pie').classList.toggle('over-fifty', n > 0.5)
var p = Math.round(n * 100);
document.getElementById('toolbar').style.background = '-webkit-linear-gradient(left, #97cc70 '+p+'%, #e0e8d9 '+p+'%)'
},
destroy(){
// document.querySelector('.pie-wrapper').style.display = 'none'
document.getElementById('toolbar').style.background = ''
}
}
}
function nextFrame(){
return new Promise(next => setTimeout(next, 10 ))
}
// -webkit-linear-gradient(left, rgb(204, 208, 230) 50%, #f7f7f7 50%)