xxxxxxxxxx
52
let song;
let amp;
let button;
let volhistory = [];
function toggleSong() {
if (song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
function preload() {
song = loadSound ('Mysong.mp3');
}
function setup() {
createCanvas(200, 200);
angleMode(DEGREES);
button = createButton('toogle');
button.mousePressed(toggleSong);
song.play();
amp = new P5.Amplitude();
}
function draw() {
background(0);
let vol = amp.getLevel();
volhistory.push(vol);
stroke(255);
noFill();
translate(width / 2, height / 2);
beginShape();
for (let i= 0; i < 360; i++) {
let r = map(volhistriy[i], 0,1,10,100);
let x = r * cos(i);
let y = r * sin(i);
vertex(x, y);
}
endShape();
if(volhistory.length >360) {
volhistory.splice(0, 1);
}
}