1
1
// ====================
2
- // DEMO: P5.Panner3D: use mouseX and mouseY to control panners X and Y
3
- // panners positionZ moves from -10000 to 10000
2
+ // DEMO: P5.Panner3D: Moves sound in 3D space from max negative coordinates, to max positive
4
3
// ====================
5
4
6
5
7
6
var soundFile ;
8
7
var panner3d ;
9
- var zPos , ZDir ;
10
8
var description , position ;
11
9
12
10
function preload ( ) {
13
11
soundFormats ( 'mp3' , 'ogg' ) ;
14
- soundFile = loadSound ( '../files/beat ' ) ;
12
+ soundFile = loadSound ( '../files/lucky_dragons_-_power_melody ' ) ;
15
13
}
16
14
15
+ var i ;
16
+ var factorI ;
17
17
function setup ( ) {
18
- createCanvas ( 500 , 500 ) ;
19
- soundFile . volume = .6 ;
18
+ createCanvas ( 500 , 500 , WEBGL ) ;
19
+
20
20
21
- //disconnect sound file and send it to output via Panner3D
22
- soundFile . disconnect ( ) ;
23
- panner3d = new p5 . Panner3D ( ) ;
24
- soundFile . connect ( panner3d ) ;
25
- soundFile . loop ( ) ;
26
- zPos = 0 ;
27
- zDir = 0.5 ;
28
-
29
- description = createDiv ( 'Panner3D: Control the the panners ' +
30
- 'positionX and positionY with the mouse ' +
31
- 'positionZ pans from -100 to 100' )
32
- position = 'positionX: 0' + 'positionY: 0' + 'positionZ: 0' ;
21
+ description = createDiv ( 'Panner3D: The cone symbolizes the soundFile ' +
22
+ 'which is panning the soundin relation to the center of the ' +
23
+ 'canvas' ) ;
33
24
p2 = createDiv ( position ) ;
34
25
35
26
description . position ( 550 , 0 ) . size ( 400 , 50 ) ;
36
27
p2 . position ( 550 , 50 ) ;
37
28
29
+ panner1 = new p5 . Panner3D ( ) ;
30
+
31
+
32
+ i = 0 ;
33
+ factorI = 1 ;
34
+ soundFile . disconnect ( ) ;
35
+ soundFile . loop ( ) ;
36
+ soundFile . connect ( panner1 ) ;
38
37
}
39
38
40
39
function draw ( ) {
41
40
background ( 0 ) ;
41
+
42
+ if ( i > 500 || i < - 500 ) { factorI = - 1 * factorI ; }
43
+
42
44
updateDescription ( ) ;
45
+
46
+ push ( ) ;
47
+ translate ( i += factorI * 1 , i + factorI * 1 , i + factorI * 1 ) ;
48
+ rotateX ( frameCount * 0.01 ) ;
49
+ rotateY ( frameCount * 0.01 ) ;
50
+ rotateZ ( frameCount * 0.01 ) ;
51
+ cone ( 100 ) ;
52
+ pop ( ) ;
43
53
44
- //Pan the sound in the Z direction
45
- if ( zPos > 50 || zPos < - 50 ) {
46
- zDir = - zDir ;
47
- }
48
- zPos += zDir ;
54
+ //pan the sound along with the cone
55
+ panner1 . set ( i * 10 , i * 10 , i * 10 ) ;
49
56
50
- //Position the sound in 3 dimensions
51
- panner3d . position ( max ( min ( 25 * ( mouseX - width / 2 ) , 6500 ) , - 6500 ) ,
52
- max ( min ( 25 * ( mouseY - width / 2 ) , 6500 ) , - 6500 ) ,
53
- max ( min ( 200 * zPos , 10000 ) , - 10000 ) ) ;
54
- ellipse ( width / 2 , height / 2 , 20 , 20 ) ;
55
- fill ( 255 , 0 , 0 ) ;
56
- ellipse ( mouseX , mouseY , 20 , 20 )
57
57
58
58
}
59
59
60
60
function updateDescription ( ) {
61
- position = 'positionX: ' + panner3d . positionX ( ) +
62
- '<br>positionY: ' + panner3d . positionY ( ) +
63
- '<br>positionZ: ' + panner3d . positionZ ( ) ;
61
+ position = 'positionX: ' + panner1 . positionX ( ) +
62
+ '<br>positionY: ' + panner1 . positionY ( ) +
63
+ '<br>positionZ: ' + panner1 . positionZ ( ) ;
64
64
p2 . html ( position ) ;
65
65
}
0 commit comments