let buttons = ["Its Yours", "Dance On My Skin", "East of Eden", "Loathe"];
let img;
let font;
let fft;
let freqs = ["bass", "lowMid", "mid", "highMid", "treble"];
let song1;
let song2;
let song3;
let song4;
function preload() {
song1 = loadSound("songs/itsyours.mp3");
song2 = loadSound("songs/danceonmyskin.mp3");
song3 = loadSound("songs/eastofeden.mp3");
song4 = loadSound("songs/loathe.mp3");
img = loadImage("images/coldsun.jpg");
font = loadFont("font/Akshar-VariableFont_wght.ttf");
}
function setup() {
createCanvas(1000, 800);
textFont(font);
noStroke();
let button1 = createButton(buttons[0]);
button1.position(0, 550);
button1.size(width / 4, 100);
button1.style("textFont", "font");
button1.style("font-size", "25px");
button1.mousePressed(playSong1());
let button2 = createButton(buttons[1]);
button2.position(250, 550);
button2.size(width / 4, 100);
button2.style("textFont", "font");
button2.style("font-size", "25px");
button2.mousePressed(playSong2());
let button3 = createButton(buttons[2]);
button3.position(500, 550);
button3.size(width / 4, 100);
button3.style("textFont", "font");
button3.style("font-size", "25px");
button3.mousePressed(playSong3());
let button4 = createButton(buttons[3]);
button4.position(750, 550);
button4.size(width / 4, 100);
button4.style("textFont", "font");
button4.style("font-size", "25px");
button4.mousePressed(playSong4());
fft = new p5.FFT();
}
function draw() {
background(28);
tint(150);
image(img, width / 4, 0, 500, 500);
let spacing = width / 10;
let margin = spacing / 5;
let spectrum = fft.analyze();
for (let i = 0; i < 10; i = i + 1) {
let x = margin + spacing * i;
for (let j = 0; j < 5; j = j + 1) {
let y = margin + spacing * j;
let idx = i * j;
let amp = map(idx, 0, 59, 0, 4);
noStroke();
let energy = fft.getEnergy(freqs[floor(amp)]);
let w = map(energy, 0, 255, 30, 80);
let z = 255 - energy;
fill(255, z, z);
square(x, y, w, 5);
}
}
}
function playSong1() {
song1.play();
song2.stop();
song3.stop();
song4.stop();
}
function playSong2() {
song2.play();
song1.stop();
song3.stop();
song4.stop();
}
function playSong3() {
song3.play();
song2.stop();
song1.stop();
song4.stop();
}
function playSong4() {
song4.play();
song2.stop();
song3.stop();
song1.stop();
}
function keyTyped() {
if (key == " ") {
song1.stop();
song2.stop();
song3.stop();
song4.stop();
}
}