xxxxxxxxxx
54
//var mic;
var song;
var button;
var amp;
var volhistory = [];
function toggleSong() {
if (song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
function preload() {
song = loadSound("rnb.mp3");
}
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
song.play();
button = createButton("toggle");
button.mousePressed(toggleSong);
amp = new p5.Amplitude();
}
function draw() {
background(0);
var vol = amp.getLevel();
console.log(vol);
volhistory.push(vol);
stroke(255);
noFill();
translate(width / 2, height / 2);
beginShape();
for (var i = 0; i < 360; i++) {
var r = map(volhistory[i], 0, 1, 10, 300);
var x = r * cos(i);
var y = r * sin(i);
vertex(x, y);
}
endShape();
if (volhistory.length > width - 50) {
volhistory.splice(0, 1);
}
stroke(255, 0, 0);
}