File tree 3 files changed +15
-4
lines changed
3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1
1
let yoff = 0.0 ;
2
2
let song ;
3
- let peaks = [ ] ;
4
3
let dark = true ;
5
4
let fast = false ;
6
5
7
6
function preload ( ) {
8
- song = loadSound ( '../assets/song.mp3' , ( ) => song . processPeaks ( ( result ) => peaks = result ) ) ;
7
+ song = loadSound ( '../assets/song.mp3' ) ;
9
8
}
10
9
11
10
function setup ( ) {
12
11
createCanvas ( windowWidth , windowHeight ) ;
13
12
fill ( 25 ) ;
14
13
song . loop ( ) ;
15
14
song . play ( ) ;
15
+
16
+ amplitude = new p5 . Amplitude ( ) ;
17
+ amplitude . setInput ( song ) ;
16
18
}
17
19
18
20
function draw ( ) {
19
- if ( peaks . find ( p => p . toFixed ( 1 ) === song . currentTime ( ) . toFixed ( 1 ) ) ) {
21
+ const level = amplitude . getLevel ( ) ;
22
+ if ( level >= .3 ) {
20
23
color = randomizeColor ( color ) ;
21
24
fill ( color . r , color . g , color . b ) ;
22
25
fast = ! fast ;
@@ -31,7 +34,7 @@ function draw() {
31
34
xoff += 0.01 ;
32
35
}
33
36
34
- yoff += fast ? 0.005 : 0.0005 ;
37
+ yoff += fast ? 0.0025 : 0.0005 ;
35
38
vertex ( width , height ) ;
36
39
vertex ( 0 , height ) ;
37
40
endShape ( ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ function draw() {
61
61
}
62
62
63
63
xoff += fast ? 0.000005 : 0.000001 ;
64
+
64
65
}
65
66
66
67
function x ( value ) {
Original file line number Diff line number Diff line change
1
+ p5js tests reacting to sound
2
+ < ul >
3
+ < li > < a href ='/0 '> Test 1</ a > </ li >
4
+ < li > < a href ='/1 '> Test 2</ a > </ li >
5
+ < li > < a href ='/2 '> Test 3</ a > </ li >
6
+ < li > < a href ='/3 '> Test 4</ a > </ li >
7
+ </ ul >
You can’t perform that action at this time.
0 commit comments