function readData() { let items = analyser.fftSize; let dataArray = new Float32Array(items); analyser.getFloatTimeDomainData(dataArray); let space = 255 / (items + 2); let pos = [0, 127.5]; let x = space; peak = 0; for (let i = 0; i < items; i++) { let data = (dataArray[i] * 125) + 127.5 if (Math.abs(data) > peak) { peak = data; } pos.push(x); pos.push(data); x += space; } pos.push(255, 127.5); positions = pos; } let positions = [ Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), ]; /*function draw() { readData(); let program = shaderHandler.getProgram("test"); let positionAttributeLocation = gl.getAttribLocation(program, "a_position"); var colorLocation = gl.getUniformLocation(program, "u_color"); let positionBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.DYNAMIC_DRAW); let vao = gl.createVertexArray(); gl.bindVertexArray(vao); gl.enableVertexAttribArray(positionAttributeLocation); gl.vertexAttribPointer( positionAttributeLocation, 2, gl.FLOAT, false, 0, 0); gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); gl.useProgram(program); gl.uniform4f(colorLocation, peak / 255, (255 - peak) / 255, .2, 1); gl.drawArrays(gl.LINE_STRIP, 0, positions.length / 2); let positionBuffer2 = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer2); gl.uniform4f(colorLocation, 0, 0, 1, .3); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.DYNAMIC_DRAW); gl.drawArrays(gl.POINTS, 0, positions.length / 2); requestAnimationFrame(draw); }*/ function setupSphere() { sphereData = []; let data = readData(), radData = data[0]; let sin = Math.sin, cos = Math.cos, total = sphereObject.total || 50, cTotal = (total + 1) * (total + 1), r = sphereObject.radius || 1000, rx = r / c.width, ry = r / c.height, counter = 0; for (let i = 1; i <= total; i++) { let lat = VTUtils.map(i, 0, total, 0, Math.PI, false); for (let j = 1; j <= total; j++) { let lon = VTUtils.map(j, 0, total, 0, Math.TWO_PI, false); let map = VTUtils.map(counter, 0, cTotal, 0, radData.length - 1, false); map = Math.floor(map); let realRX = rx + radData[map]; let realRY = ry + radData[map]; let x = rx * sin(lon) * cos(lat); let y = rx * sin(lon) * sin(lat); let z = ry * cos(lon); sphereData.push(x); sphereData.push(y); sphereData.push(z); counter++; } } return [VTUtils.hsvToRgb(data[1], 1, 1), data[1]]; }