-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3DFrame.html
182 lines (161 loc) · 4.62 KB
/
3DFrame.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<title>模型框架--音乐版</title>
<script src="dist/echarts.js"></script>
<script type="text/javascript" src="dist/echarts-gl.min.js"></script>
<style>
html{
height: 100%;
}
body{
height: 100%;
}
#main{
width: 100%;
height: 100%;
background-color: #111111;
}
</style>
</head>
<body>
<div id="main"></div>
<script>
var main =document.getElementById("main");
var myChart = echarts.init(main);//直接写在里面会无法找到dom的宽和高
var UPDATE_DURATION = 100;
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var oReq = new XMLHttpRequest();
oReq.open('GET', '全职高手.mp3', true);
oReq.responseType = 'arraybuffer';// XMLHttpRequest 2的新东西
oReq.onload = function(e) {
// 音频数据在oReq.response中,而不是request.requestText
audioContext.decodeAudioData(oReq.response, initVisualizer);
};
oReq.send();
function initVisualizer(audioBuffer) {
inited = true;
// create source node
var source = audioContext.createBufferSource();
source.buffer = audioBuffer;
// Must invoked right after click event
if (source.noteOn) {
source.noteOn(0);
}
else {
source.start(0);//0是当前audio context中的同步时间,要求立即开始
}
var analyzer = audioContext.createAnalyser();
var gainNode = audioContext.createGain();// create gain node
analyzer.fftSize = 4096;
gainNode.gain.value = 1;
source.connect(gainNode);
gainNode.connect(analyzer);
analyzer.connect(audioContext.destination);
var frequencyBinCount = analyzer.frequencyBinCount;
var dataArray = new Uint8Array(frequencyBinCount);
var beta = 0;
function update() {
analyzer.getByteFrequencyData(dataArray);
var item = [];
var size = 50;
var dataProvider = [];
for (var i = 0; i < size * size; i++) {
var x = i % size;
var y = Math.floor(i / size);
var dx = x - size / 2;
var dy = y - size / 2;
var angle = Math.atan2(dy, dx);
if (angle < 0) {
angle = Math.PI * 2 + angle;
}
var dist = Math.sqrt(dx * dx + dy * dy);
var idx = Math.min(
frequencyBinCount - 1, Math.round(angle / Math.PI / 2 * 60 + dist * 60) + 100
);
var val = Math.pow(dataArray[idx] / 100, 3);
dataProvider.push([x, y, Math.max(val, 0.1)]);
}
myChart.setOption({
grid3D: {
viewControl: {
beta: beta,
alpha: Math.sin(beta / 10 + 40) * (beta % 10 + 5) / 15 * 30 + 30,
distance: Math.cos(beta / 50 + 20) * (beta % 10 + 5) / 15 * 50 + 80,
animationDurationUpdate: UPDATE_DURATION,
animationEasingUpdate: 'linear'
}
},
series: [{
data: dataProvider
}]
});
beta += 2;
setTimeout(update, UPDATE_DURATION);
};
update();
}
option = {
tooltip: {},
visualMap: {
show: false,
min: 0.1,
max: 4,
inRange: {
color: ['#010103', '#2f490c', '#b0b70f', '#fdff44', '#fff']
}
},
xAxis3D: {
type: 'value'
},
yAxis3D: {
type: 'value'
},
zAxis3D: {
type: 'value',
min: -6,
max: 6
},
grid3D: {
show: false,
environment: '#000',
viewControl: {
distance: 100
},
postEffect: {
enable: true,
FXAA: {
enable: true
}
},
light: {
main: {
shadow: true,
intensity: 10,
quality: 'high'
},
ambientCubemap: {
texture: 'Image/miranda_uncropped.hdr',
exposure: 0,
diffuseIntensity: 0.2
}
}
},
series: [{
type: 'bar3D',
silent: true,
shading: 'lambert',
data: [],
barSize: 1,
lineStyle: {
width: 4
},
// animation: false,
animationDurationUpdate: UPDATE_DURATION
}]
}
myChart.setOption(option);
</script>
</body>
</html>