xxxxxxxxxx
62
let mySound;
let button;
let amp;
function preload(){
mySound = loadSound('What_It_Is.mp3');
}
function setup() {
createCanvas(600, 580);
button= createButton ("play");
button.mousePressed(togglePlaying);
colorMode(HSB, 360, 100, 100, 100);
amp = new p5.Amplitude();
}
function togglePlaying(){
if (!mySound.isPlaying()){
mySound.play();
mySound.setVolume(0.3);
button.html("pause");
} else {
mySound.pause();
button.html("play");
}
}
function draw() {
var vol = amp.getLevel ();
console.log(vol);
background(225, 0, 0, 40);
let sinVal=sin(radians(frameCount));
let freq = 4;
let speed = 1;
let ampl = 40;
for(let i = 0; i < width; i += 5){
let y = sin(radians(i + frameCount * speed)*freq) * vol *400;
// let absY = abs(y);
let dia = map(y,-vol *100, vol *400, 10, 3);
noStroke();
fill((sin(radians(frameCount))*122 + 123),100,100, 50);
ellipse(i, height / 2 + y, dia*2 , dia*2);
ellipse(i, height / 3 + y, dia/2 , dia/2);
ellipse(i, height - height /3 + y, dia/2 , dia/2);
let x = sin(radians(i + frameCount * speed)*freq) * vol *400;
ellipse(i, height / 6 + x, dia , dia);
ellipse(i, height - height/6 + x, dia , dia);
//ellipse(i, height - height /6 + x, dia , dia);
}
}