-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
57 lines (46 loc) · 1.21 KB
/
sketch.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
46
47
48
49
50
51
52
53
54
55
56
57
const binCount = 1024
let particles = new Array(binCount)
let fft
let song
let Particle = function(position) {
this.position = position
this.speed = createVector(0, 1)
this.color = [random(0, 255), random(0,255), random(0,255)]
this.draw = function() {
fill(this.color)
ellipse(
this.position.x, this.position.y,
this.diameter, this.diameter
)
}
this.update = function(level) {
this.position.y += this.speed.y * level * 10
if (this.position.y > height) {
this.position.y = 0
}
this.diameter = random(2,4) + (level * 50)
}
}
function preload() {
// body language, everything i wanted, its you, the good side, & the yaer of the monkey work best
song = loadSound('123.mp3')
fft = new p5.FFT()
}
function setup() {
createCanvas(windowWidth, windowHeight)
noStroke()
song.setVolume(0.5);
song.loop();
positionParticleWave(particles)
}
function draw() {
background(0, 0, 0, 100)
// returns an array with [binCount] amplitude readings from lowest to highest frequencies
let spectrum = fft.analyze()
updateParticles(spectrum)
}
function touchStarted() {
if (getAudioContext().state !== 'running') {
getAudioContext().resume()
}
}