-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring-on-beat.js
45 lines (41 loc) · 1.17 KB
/
ring-on-beat.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
/**
* Create expanding ring on audioanalyser beat.
*/
AFRAME.registerComponent('ring-on-beat', {
schema: {
analyserEl: { type: 'selector' },
beat: { default: 'bass' },
},
init: function () {
const analyserEl = this.data.analyserEl || this.el;
const el = this.el;
const rings = (this.rings = []);
analyserEl.addEventListener(`audioanalyser-beat-${this.data.beat}`, function () {
const ringEl = document.createElement('a-ring');
ringEl.setAttribute('material', 'opacity', '0.6');
ringEl.setAttribute('position', '0 0.1 0');
ringEl.setAttribute('rotation', '-90 0 0');
el.appendChild(ringEl);
ringEl.addEventListener('loaded', function () {
rings.push(ringEl);
setTimeout(function () {
el.removeChild(ringEl);
rings.splice(rings.indexOf(ringEl), 1);
}, 2000);
});
});
},
/**
* Expand ring radii.
*/
tick: function () {
this.rings.forEach(function (ringEl) {
const scale = ringEl.getAttribute('scale');
ringEl.setAttribute('scale', {
x: scale.x * 1.06 + 0.05,
y: scale.y * 1.06 + 0.05,
z: scale.z,
});
});
},
});