-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
37 lines (30 loc) · 876 Bytes
/
worker.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
let offCanvas;
let offContext;
let width;
let height;
self.onmessage = function(e) {
if(e.data.msg === 'init') {
offCanvas = e.data.canvas;
offContext = offCanvas.getContext('2d');
width = offCanvas.width;
height = offCanvas.height;
}else{
const dataArray = e.data.dataArray;
const bufferLength = e.data.bufferLength;
offContext.clearRect(0, 0, width, height);
offContext.fillStyle = 'rgb(0, 0, 0)';
offContext.fillRect(0, 0, width, height);
var barWidth = (width / bufferLength) * 2.5;
var barHeight;
var x = 0;
for(var i = 0; i < bufferLength; i++) {
barHeight = dataArray[i]/2;
offContext.fillStyle = 'rgb(' + (barHeight+100) + ',50,50)';
offContext.fillRect(x,height-barHeight/2,barWidth,barHeight);
x += barWidth + 1;
}
}
};
self.postMessage({
topic: 'done'
});