JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<section id="links">
<a target="_blank" href="https://codepen.io/Rumyra/pen/NbdXaE?editors=1010">View over Https</a>
<a target="_blank" href="https://codepen.io/Rumyra/post/audiovis-codevember-9-10">Read Blog Post</a>
</section>
<div id="screen">
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
<section><div>
<span data-freq="low"></span>
<span data-freq="mid"></span>
<span data-freq="high"></span>
</div></section>
</div>
html {background:#efefef; font-family:"Lato", "Lucida Grande","Lucida Sans Unicode", Tahoma, Sans-Serif; letter-spacing:-0.2px;}
body {margin:0px; padding:0px; overflow:hidden;}
#links {
display:flex; padding:5px;
justify-content:space-around;
a {
display:block; padding:5px 15px;
border: 3px solid #343436; border-radius: 3px;
background-color:#343436;
text-align:center; text-decoration:none; color:#fff;
&:hover {background-color:#4d4d50;}
}
}
#screen {
position: relative;
width:100vw; height:100vh;
background-color: black;
section {
height: 30vh; width:100vw;
position:absolute; left:0px; bottom:0px;
div {
height:30vh; width:100vw;
display: flex;
justify-content: space-around;
align-items: flex-end;
border-bottom:2px solid hsla(
calc(10*var(--midFreqTwo)),
60%,
60%,
0.7)
;
span {
display: block;
width: calc(10vw*var(--lowFreqOne)); height: 20vh;
border-radius: 7vw 7vw 0 0;
background-color:hsla(300, 60%, 60%, 0.7);
border:2px solid black;
border-bottom-width: 0px;
&:nth-of-type(1) {
display: block;
width: calc(30vw*var(--lowFreqOne));
height: calc(20vh*var(--lowFreqThree));;
border-radius: calc(20vw*var(--lowFreqThree)) calc(20vw*var(--lowFreqOne)) 0 0;
background-color:hsla(
calc(10*var(--lowFreqTwo)),
60%,
60%,
0.7)
;
}
&:nth-of-type(2) {
display: block;
width: calc(30vw*var(--midFreqOne));
height: calc(20vh*var(--midFreqThree));;
border-radius: calc(20vw*var(--midFreqThree)) calc(20vw*var(--midFreqOne)) 0 0;
background-color:hsla(
calc(10*var(--midFreqTwo)),
60%,
60%,
0.7)
;
}
&:nth-of-type(3) {
display: block;
width: calc(30vw*var(--highFreqOne));
height: calc(20vh*var(--highFreqThree));;
border-radius: calc(20vw*var(--highFreqThree)) calc(20vw*var(--highFreqOne)) 0 0;
background-color:hsla(
calc(10*var(--highFreqTwo)),
60%,
60%,
0.7)
;
}//nth
}//span
}//div
}//section
}
// set up audio context
var audioContext = (window.AudioContext || window.webkitAudioContext);
// create audio class
if (audioContext) {
// Web Audio API is available.
var audioAPI = new audioContext();
} else {
// Web Audio API is not available. Ask the user to use a supported browser.
alert("Oh nos! It appears your browser does not support the Web Audio API, please upgrade or use a different browser");
}
// variables
var analyserNode,
frequencyData = new Uint8Array(256);
const screen = document.querySelector('#screen'),
waves = document.querySelectorAll('#screen section'),
totalEls = waves.length;
// create an audio API analyser node and connect to source
function createAnalyserNode(audioSource) {
analyserNode = audioAPI.createAnalyser();
analyserNode.fftSize = 512;
audioSource.connect(analyserNode);
}
// get's html elements, loops over them & attaches a frequency from analysed data - what you do is up to you!
function animateStuff() {
requestAnimationFrame(animateStuff);
analyserNode.getByteFrequencyData(frequencyData);
document.documentElement.style.setProperty('--lowFreqOne', frequencyData[3]/255);
document.documentElement.style.setProperty('--lowFreqTwo', Math.floor(frequencyData[10]/4));
document.documentElement.style.setProperty('--lowFreqThree', frequencyData[20]/255);
document.documentElement.style.setProperty('--midFreqOne', frequencyData[30]/255);
document.documentElement.style.setProperty('--midFreqTwo', Math.floor(frequencyData[45]/4));
document.documentElement.style.setProperty('--midFreqThree', frequencyData[60]/255);
document.documentElement.style.setProperty('--highFreqOne', frequencyData[80]/255);
document.documentElement.style.setProperty('--highFreqTwo', Math.floor(frequencyData[100]/4));
document.documentElement.style.setProperty('--highFreqThree', frequencyData[110]/255);
}
for (let i=0; i<totalEls; i++) {
waves[i].animate([
// keyframes
{ transform: 'translateY(0vh)' },
{ transform: 'translateY(-100vh)' }
], {
// timing options
duration: 3000,
delay: i*100,
iterations: Infinity
});
console.log(i*100);
}
// getUserMedia success callback -> pipe audio stream into audio API
var gotStream = function(stream) {
// Create an audio input from the stream.
var audioSource = audioAPI.createMediaStreamSource(stream);
createAnalyserNode(audioSource);
animateStuff();
}
// pipe in analysing to getUserMedia
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(gotStream);
Also see: Tab Triggers