@@ -13,58 +13,38 @@ function preload() {
1313
1414function setup ( ) {
1515 createCanvas ( 400 , 400 ) ;
16- background ( 0 , 0 , 0 ) ;
1716
1817 soundFile . volume = .6 ;
1918
2019 // create the ball
21- ball = ellipse ( )
22- ball . x = width / 2 ;
23- ball . y = height / 2 ;
24- ball . speed = 7 ;
25- ellipse ( ball . x , ball . y , 100 , 100 ) ;
20+ ball = {
21+ x : width / 2 ,
22+ y : height / 2 ,
23+ speed : 7
24+ }
2625}
2726
2827function draw ( ) {
29- background ( 0 , 0 , 0 ) ;
28+ background ( 0 ) ;
3029
3130 ball . x += ball . speed ;
3231
3332
3433 // when the ball hits the wall...
35- if ( ball . x > width ) {
36-
37- // map the ball's x location to a panning degree (float between -1.0 and 1.0)
38- var panning = map ( ball . x , 0. , width , - 1.0 , 1.0 ) ;
39- soundFile . pan ( panning ) ;
40-
41-
42- // set a random playback speed for the sound
43- var newSpeed = Math . random ( ) ;
44- ball . speed = - ( ball . speed ) ;
45- soundFile . rate ( newSpeed ) ;
46-
47- // play the sound
48- soundFile . play ( ) ;
49- }
50-
51- if ( ball . x < 0 ) {
34+ if ( ball . x > width || ball . x < 0 ) {
5235
5336 // map the ball's x location to a panning degree (float between -1.0 and 1.0)
54- var panning = map ( ball . x , 0. , width , - 1.0 , 1.0 ) ;
37+ var panning = map ( ball . x , 0 , width , - 1 , 1 ) ;
5538 soundFile . pan ( panning ) ;
5639
5740 // set a random playback speed for the sound
58- var newSpeed = Math . random ( ) ;
59- ball . speed = - ( ball . speed ) ;
41+ var newSpeed = random ( 1 ) ;
42+ ball . speed = - ball . speed ;
6043 soundFile . rate ( newSpeed ) ;
6144
6245 // play the sound
6346 soundFile . play ( ) ;
64-
6547 }
66-
67- ellipse ( ball . x , ball . y , 100 , 100 )
68-
48+ ellipse ( ball . x , ball . y , 100 , 100 ) ;
6949}
7050
0 commit comments