var useRectangles = true;
var useTriangles = false;
soundFile = loadSound("Edward Maya & Vika Jigulina - Stereo Love (Officia.mp3");
createCanvas(windowWidth, windowHeight);
amplitude = new p5.Amplitude();
amplitude.setInput(soundFile);
fftColor = color(random(256), random(256), random(256), 15);
var button = createButton('Toggle Shape');
button.mousePressed(toggleShape);
var level = map(amplitude.getLevel(), 0, 1, 1, 10);
var scaling = map(amplitude.getLevel(), 0, 1, 1, 20);
if (level > 4.5 && level < 5.5) {
} else if (level > 5.5 && millis() - lastTime >= 1000) {
fftColor = color(random(256), random(256), random(256), 15);
rect(width / 2, height / 2, level * 25, level * 25);
} else if (useTriangles) {
triangle(width / 2, height / 2 - level * 12.5, width / 2 - level * 12.5, height / 2 + level * 12.5, width / 2 + level * 12.5, height / 2 + level * 12.5);
ellipse(width / 2, height / 2, level * 25, level * 25);
stroke(color(random(256), random(256), random(256)));
particleArray.push(new Particle(random(width * 0.5 - level * 25, width * 0.5 + level * 25), random(height * 0.5 - level * 12.5, height * 0.5 + level * 12.5), random(-scaling, scaling), random(-scaling, scaling), level));
for (var i = 0; i < particleArray.length; i = i + 1) {
if (particleArray[i].alive) {
particleArray[i].display();
particleArray.splice(i, 1);
var Particle = function (x, y, speedX, speedY, level) {
this.color = color(random(256), random(256), random(256), random(75));
this.radius = random(10, 50);
this.rotation = random(0, TWO_PI);
this.rotationSpeed = random(0.01, 0.1);
this.move = function () {
this.x = this.x + this.speedX;
this.y = this.y + this.speedY;
this.rotation = this.rotation + this.rotationSpeed;
if (this.x + this.radius < 0 || this.x - this.radius > width || this.y + this.radius < 0 || this.y - this.radius > height) {
this.display = function () {
translate(this.x, this.y);
rect(0, 0, this.radius + this.level * 10, this.radius + this.level * 10);
} else if (useTriangles) {
triangle(0, -this.level * 12.5, -this.level * 12.5, this.level * 12.5, this.level * 12.5, this.level * 12.5);
ellipse(0, 0, this.radius + this.level * 10, this.radius + this.level * 10);
var spectrum = fft.analyze();
translate(0, 0 - windowHeight / 1.5);
for (i = 0; i < spectrum.length; i++) {
var y = map(amp, 0, 1, height, 0);
translate(windowWidth, windowHeight + windowHeight / 1.5);
for (i = 0; i < spectrum.length; i++) {
var y = map(amp, 0, 1, height, 0);
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
} else if (useTriangles) {