Menu at the top right, stop button at the bottom left. Only works on Chrome.
xxxxxxxxxx
let count = 0;
let xPos = [];
let yPos = [];
let size = [];
let fft, img, settings, jukebox, songs;
let button;
function preload() {
songs = [
loadSound('Hans_Zimmer_-_Interstellar_Main_Theme_Abandoned_Remix.mp3'), //Loading 3 songs
loadSound('JJ_-_Still_Mp3Gooru_1.mp3'),
loadSound('Platform_9_-_Oneeva.mp3')
]
img = loadImage('download.png')
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
settings = { //Creating the Settings for the dat.GUI
Orbit_Speed: 0.015,
Change_Song: songs[0],
};
jukebox = settings.Change_Song; //Declaring source of music and the FFT
jukebox.stop(); //help!!
fft = new p5.FFT();
fft.setInput(jukebox);
let gui = new dat.GUI();
gui.add(settings, 'Orbit_Speed', 0.000, 0.1);
let songSetting = gui.add(settings, 'Change_Song', {
'Interstellar Theme remix': 0,
'Still Dre Remix': 1,
'Platform 9': 2
}); // Meant to allow people to change the song (Needs to be F I X E D)
songSetting.onChange(function(value) { //Changing the music
jukebox.stop();
jukebox = songs[settings.Change_Song];
//console.log(settings);
jukebox.play();
refresh();
button = createButton('Stop');
button.position(100, height - 100, 400);
button.mousePressed(pause);
});
for (let index = 0; index < 400; index++) { //Generating boundaries for stars
xPos[index] = random(-width, width);
yPos[index] = random(-height, height);
size[index] = random(1, 5);
}
colour = random(130, 255);
}
function pause(){ //Stop button
if(jukebox.play = true){
jukebox.stop();
}
}
function refresh(){ //Ensures the next song has their fft recognised
fft = new p5.FFT();
fft.setInput(jukebox);
}
function draw() {
background(0);
fill(colour);
for (let i = 0; i < 400; i++) { //Creating the Stars
ellipse(xPos[i], yPos[i], size[i]);
}
sunEarth(); //Implementing function to add in the Sun and the Earth
}
function sunEarth(xPos, yPos, size) {
let spectrum = fft.analyze(); //Declaring the frequency range
let innerCore = fft.getEnergy(60, 200); //Creating boundaries for the layers of the earth to oscillate
let outerCore = fft.getEnergy(200, 400);
let mantle = fft.getEnergy(400, 800);
let flareOne = fft.getEnergy(800, 2000); //Creating boundaries for sun flares to oscillate
let flareTwo = fft.getEnergy(1000, 3000);
let flareThree = fft.getEnergy(1200, 4000);
let sizeMantle = map(mantle, 0, 1, 60 / 95, 100 / 95); //Mapping the boundaries to Earth's core
let sizeOuterCore = map(outerCore, 0, 1, 30 / 100, 55 / 100);
let sizeInnerCore = map(innerCore, 0, 1, 10 / 100, 28 / 100);
let sizeFlareOne = map(flareOne, 0, 1, 300 / 80, 490 / 80); //Mapping the boundaires to Sun flares
let sizeFlareTwo = map(flareTwo, 0, 1, 310 / 80, 500 / 80);
let sizeFlareThree = map(flareThree, 0, 1, 350 / 80, 620 / 80);
noStroke();
fill(255, 255, 0); //Sun
ellipse(0, 0, 300);
fill(255, 255, 150, 75); //3rd Sun flare
ellipse(0, 0, sizeFlareThree);
fill(255, 255, 100, 50); //2nd Sun flare
ellipse(0, 0, sizeFlareTwo);
fill(255, 255, 50, 150); //1st Sun flare
ellipse(0, 0, sizeFlareOne);
rotateY(count); //Controlling the distance Earth orbits around the sun
rotateX(count);
translate(400, -100, 20);
rotateX(-count);
rotateY(-count);
texture(img); //Image of the earth
ellipse(0, 0, 100);
fill(255, 0, 0); //Mantle Layer
ellipse(0, 0, sizeMantle);
fill(255, 100, 0); //Outer Core Layer
ellipse(0, 0, sizeOuterCore);
fill(255, 200, 0); //Inner Core Layer
ellipse(0, 0, sizeInnerCore);
count += settings.Orbit_Speed; //Orbit speed/period
}