music visualizer; click circular refresh button to start; mouse click and drag to explore; flashing colors warning
xxxxxxxxxx
//fork of Bumpy Ride by Richard Bourne https://openprocessing.org/sketch/825688 & 200120 by Sayama https://openprocessing.org/sketch/825511
//tentacle/kraken by https://sketchfab.com/3d-models/tentacles-daddd60eb82c4c5592baf16a98151bae
//lightning video by <a href="https://pixabay.com/users/11455326-11455326/?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=166697">11455326</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=166697">Pixabay</a>
//3D ship by https: sketchfab.com/3d-models/pirate-ship-fe0ea2cee119476fb1a7524d5ff380dc
//music by <a href="https://pixabay.com/users/grand_project-19033897/?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=128378">Grand_Project</a> from <a href="https://pixabay.com/music//?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=128378">Pixabay</a>
//thunder Sound Effect by <a href="https://pixabay.com/users/placidplace-25572496/?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=86150">Peace,love,happiness</a> from <a href="https://pixabay.com/sound-effects//?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=86150">Pixabay</a>
//kraken Sound Effect from <a href="https://pixabay.com/?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=68135">Pixabay</a>
let songCounter=0
let gridNum = 40;
let w,step;
let sp = -30;
let y;
let countdown=true
let counter=0
let choice=0
let choiceCounter=0
let colorWavesBlue=true
let choiceUnknown=true
let tentacleCounter=0
function preload()
{
tentacle = loadModel('tentacles.obj', true); //loads tentacle
pirateShip = loadModel('pirateShip.obj', true); //loads pirate ship
soundFormats('mp3', "wav");
song = loadSound('epicMusic.mp3');//load song
stormSounds = loadSound('thunder.mp3');//load stormy backgrounds music
krakenSounds = loadSound('krakenSounds.mp3');//load kraken sounds
video = createVideo('storm.mp4'); //loads lightning video
}
function setup()
{
OPC.toggle("Unleash_the_kraken",false) //creates buttons at top right of screen
OPC.toggle("kraken_Calling",false)
video.hide() //hides video from automatically being/playing in foreground
video.loop() //loops video continuosly
stormSounds.play() //starts storm sounds
stormSounds.loop() //loops storm sounds
song.play() //starts song - Doing this the song also plays with the storm sounds playing at same time
song.loop() //loops song
amp = new p5.Amplitude(); //used to get sound amplitude
createCanvas(1512, 834,WEBGL);
w = width;
step = w/gridNum;
}
function draw()
{
if(kraken_Calling==true) //if user clicks button to hear the kraken calling
{
if(krakenSounds.isPlaying()==false) //if kraken mp3 is not playing automatically
{
krakenSounds.play() //play kraken mp3
}
}
else krakenSounds.stop() //else stop the kraken mp3
vol = amp.getLevel(); //gets volume
volumeLevel = round(map(vol, 0, 0.3,5, 60)); //gives us a variable for the volume of "all" music/sounds, and converts that volume range to now be between 5 and 60
frameRate(volumeLevel) //makes frame Rate the speed of volumrLevel; 5 to 60
//this code here makes the "counter" variable count up and down between -.15 to .15 continuously, to tilt the ship left and right
//at the speed of the volume of the music
if(countdown==true) counter=counter-volumeLevel/2830 //to determine the sway/tilt speed we divide volumeLevel by 2830, to keep the counter incrimenting/deincrimenting at a very very small
else counter=counter+volumeLevel/2830 //variable
if(counter>=.15) countdown=true
else if(counter<=-.15) countdown=false
orbitControl() //allows player to click and drag the sketch!
if(volumeLevel>50) background(random(100,140)) //if volume loud, background (area outside where the animated sketch is in) flashes brighter
else background(random(40)) //else background flashes darker
//code below gives us a 4 second wait if theChoice=0.
//This is done because volumeLevel caps at 60. When the volumeLevel reached 60,
//I wanted the ship, kracken, etc. to turn white/transparent. However the volumeLevel capped at 60
//during some parts of the song - for a "long" period of time, making the ship, kraken, etc. stay white and
//transparent, causing lag. Code below esentially makes it so if volumeLevel reaches 60, and theChoice=0,
//ship, kracken, etc. to turn white/transparent for 4 seconds, then theChoice is randomized again, making everything
//colored again.
if(choiceUnknown==true) theChoice=round(random(4))
if(theChoice==0)
{
choiceUnknown=false
choiceCounter++
if(choiceCounter>=(60*4))
{
choiceUnknown=true
}
}
if(volumeLevel>=60 & theChoice==0)
{
pixelDensity(.4) //lessens pixel density in attempt to decrease lag
stroke(0)
noFill() //make waves transparent
colorWavesBlue=false
}
else
{
colorWavesBlue=true //make waves not transparent, but colored
pixelDensity(.7) //higher pixel density due to not much lag visibile when everythgin is colored
noStroke()
}
//wave creation
rotateX(PI*(0.35 + 0.1*sin(frameCount/30)));
scale(0.9 + 0.1*sin(frameCount/35));
translate(-w*0.5,-w*0.5);
for(y = -400-(45*15); y < w-480+(95*5); y += step)
{
beginShape(TRIANGLE_STRIP);
for(let x = -500; x < w+500; x += step)
{
if(colorWavesBlue==true)
{
fill(0,0,random(50)) //makes waves colored blue/black
}
vertex(x,y,noiseVal(x,y + frameCount*sp)-200);
vertex(x,y + step,noiseVal(x,y + step + frameCount*sp)-200);
}
endShape();
}
push()
if(volumeLevel>=60 & theChoice==0)
{
stroke(0)//make ship transparent
noFill()
}
else
{
stroke(random(40),0,0)//color ship
fill(random(40),0,0)
}
//places ship on wave center updated point
translate(795.4, 28.20000000000014,noiseVal(795.4, 28.20000000000014 + frameCount*sp)+125.7+56.779-200);
rotateX(-4.491+random(-.015,.015)-.49-0.121+counter/2) //tilt ship forward back
rotateY(-3.112)
rotateZ(counter)//left right rotate
scale(4)
model(pirateShip)//places ship model
pop()
tentacleCounter=tentacleCounter-.05 //speed that the tentacle rotates at. This is negative to make rotation of tentacle spin in opposite direction
if(Unleash_the_kraken==true) //if user clicks button on top right to unleash the kraken
{
push()
scale(53)
translate(21.5,-72.5,21.5-10) //kracken placement
if(volumeLevel>=60 & theChoice==0) //applies volume changes to the kranken/tentacle
{
pixelDensity(.4)
stroke(0)
noFill() //makes kracken transparent
}
else
{
fill(random(10),0,0,random(255)) //colors kracken
}
rotateY(tentacleCounter)
model(tentacle)
pop()
}
push() //adds skydome - giant sphere everything is inside
rotateX(random(255)) //rotates sphere randomly every frame for more realistic 3D storm look
rotateY(random(255))
rotateZ(random(255))
texture(video) //adds storm/lightening video to the sphere
sphere(random(2300,5000)) //randomises sphere size to increase 3d effect
pop()
}
function noiseVal(x,y)
{
let m = 0.002;
let h = height*0.25;
return (noise(x*m,y*m) -0.5)*2* h;
}