xxxxxxxxxx
var button, song, amplitude, fft;
var ready=true;
function setup() {
createCanvas(windowWidth, windowHeight);
song = loadSound('alina.ogg');
amplitude = new p5.Amplitude();
fft = new p5.FFT();
rot=0;
noStroke();
textSize(width*.1);
text('click!', .4*width, height/2);
}
function draw() {
if (!ready) {
background(0, 0, 50);
textSize(width*.1);
fill(0,255,128,.01*frameCount);
text('Happy',width*.35,.2*height);
text('2019 !',width*.35,.9*height);
var level=pow(amplitude.getLevel(), .5);
var spectrum = fft.analyze();
push();
translate(width/2, height/2);
var coeff1=.1+.1*sin(.001*frameCount);
var coeff2=.1+.1*cos(.0015*frameCount);
for (i = 0; i<300; i++) {
fill(128*(1+sin(.05*spectrum[i])), 512*level, 128*(1+cos(.05*spectrum[i])), 50);
ellipse(width*level*(.5*sin(coeff1*spectrum[i])), height*level*(.5*cos(coeff2*spectrum[i])), spectrum[i]*width/1920, spectrum[i]*width/1920);
}
pop();
}
}
function mousePressed() {
if (song.isLoaded()) {
if (ready) {
song.play();
ready=false;
}
} else alert('Sound file is loading...');
}