Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="controls">
    <div id="loading">Loading audio..</div>
  
    <button id="toggle_audio" class="pause"></button>
    <p>Inkqualizer</p>
</div>
<div id="credits">
    I don't own the audio.
</div>
<!-- HTML elements for the ink tanks -->
<div id="equalizer_container">
    <div class="ink_tank first">
        <div class="ink orange">
            <div class="ink_surface"></div>
            <div class="ink_empty"></div>
        </div>
    </div>
    <div class="ink_tank">
        <div class="ink yellow">
            <div class="ink_surface"></div>
            <div class="ink_empty"></div>
        </div>
    </div>
    <div class="ink_tank">
        <div class="ink green">
            <div class="ink_surface"></div>
            <div class="ink_empty"></div>
        </div>
    </div>
    <div class="ink_tank">
        <div class="ink purple">
            <div class="ink_surface"></div>
            <div class="ink_empty"></div>
        </div>
    </div>
    <div class="ink_tank">
        <div class="ink magenta">
            <div class="ink_surface"></div>
            <div class="ink_empty"></div>
        </div>
    </div>
</div>

              
            
!

CSS

              
                @font-face{
    font-family: 'Splatoon';
    src: url('//s.cdpn.io/12109/Splatoon.eot');
    src: url('//s.cdpn.io/12109/Splatoon.eot?#iefix') format('embedded-opentype'),
         url('//s.cdpn.io/12109/Splatoon.woff2') format('woff2'),
         url('//s.cdpn.io/12109/Splatoon.woff') format('woff'),
         url('//s.cdpn.io/12109/Splatoon.ttf') format('truetype'),
         url('//s.cdpn.io/12109/Splatoon.svg#Splatoon') format('svg');
    font-weight: normal;
    font-style: normal;
}

body{
    background:#1f1f38;
    overflow:hidden;
}
*{font-family: 'Splatoon', Arial;
    font-weight: normal;
    font-size:34px;
    color:#aadc00;
    letter-spacing:2px;
}

#equalizer_container{
    width:1280px; height:720px;
    background: url(https://s.cdpn.io/12109/bg.jpg) 0 0 no-repeat;
    position:absolute; left:50%; top:0px; margin-left:-640px;
    border-radius:16px;
    box-shadow:inset 0 0 16px 5px #1f1f38;
}

.ink_tank{
    width:162px; height:459px;
    overflow:hidden;
    position:relative; float:left;
    margin-top:137px; margin-right:60px;
}
.ink_tank:before{
    content:"";
    width:100%;height:100%;
    background: url(https://s.cdpn.io/12109/ink_tank.png) 0 0 no-repeat;
    position:absolute; left:0px; top:0px;
    z-index:10;
}

.ink_tank.first{ margin-left:112px; }

.ink_tank .ink{
    width:122px; height:358px;
    position:absolute; left:20px; top:59px;
    background: url(https://s.cdpn.io/12109/ink.png) 0 0 no-repeat;
    overflow:hidden;
}
.ink.orange{    background-position:0px 0px; }
.ink.yellow{    background-position:-122px 0px; }
.ink.green{     background-position:-244px 0px; }
.ink.purple{    background-position:-366px 0px; }
.ink.magenta{   background-position:-488px 0px; }

.ink_surface{
    width:122px; height:96px;
    background: url(https://s.cdpn.io/12109/ink_surface.png);
    background-repeat:no-repeat;
    background-position:0px 0px;

    position:absolute; left:0px;top:1px;
    z-index:7; 
    transform-style: preserve-3d;
}
.ink_empty{
    width:122px; height:1px;
    background: #20201b;
    position:absolute; left:0px;top:0px;
    z-index:5;
    transform-style: preserve-3d;
}
#controls{
    width:1280px;height:128px;
    position:absolute;
    left:50%;top:570px;margin-left:-640px;
    z-index:100;
    text-align:center;
    display:block;
}

#toggle_audio{
    float:left;
    width:111px; height:111px;
    background:url(https://s.cdpn.io/12109/toggle_audio.png) 0 0 no-repeat;
    position:absolute;right:0px;top:0px;
}
#toggle_audio.pause{
    background-position:-111px 0px;
}

button{
    cursor:pointer;
    border:none;
    outline:none;
}
button:hover{
    transform: rotate(5deg) scale(1.1,1.1);
    transition:transform 0.1s ease;
}
#play_splatoon_music{
    width:96px;height:96px;
    position:absolute;left:0px;top:10px;
    border-radius:18px;
    background: url(https://31.media.tumblr.com/avatar_3535825f7605_128.png) 0 0 no-repeat;
    background-size:96px 96px;
}
#play_beat_loop{
    width:96px;height:96px;
    position:absolute;left:106px;top:10px;
    border-radius:18px;
    background: url(https://s.cdpn.io/12109/mj.png) 0 0 no-repeat;
}
#loading{
    width:1280px;height:48px;line-height:32px;
    color:#df36a5;
    position:absolute;left:0px;top:0px;
    display:none;
}
#credits{
    font-family:Arial;
    color:#843291;
    font-size:11px;
    width:100%; height:26px;
    position:absolute;left:0px;bottom:0px;
    text-align:center;
    letter-spacing:1px;
}

#drag_drop_area{
    border-radius:16px;
    width:96px;height:96px;
    border:3px dashed #aadc00;
    position:absolute;
    right:121px;top:0px;
    background:#1f1f38;
    box-shadow: 0 0 6px 2px transparent;
    transition:all 0.1s ease;
}
#drag_drop_area:before{
    content:'\2714';
    font-family:Arial;
    font-size:48px; line-height:96px;
    width:96px;height:96px;
    border-radius:16px;
    position:absolute;left:0px;top:0px;
    pointer-events:none;
    display:none;
}
#drag_drop_area:after{
    content:"Drag n drop music here!";
    font-size:21px;line-height:24px;
    pointer-events:none;
    width:180px;height:56px;
    position:absolute;left:-48px;top:-64px;
    transform: rotate(-10deg);
}
#drag_drop_area:hover, #drag_drop_area:active, #drag_drop_area.drop_aware{
    border-color:#fff;
    background:#2e2e54;
}
#drag_drop_area.drop_animate:before{
    display:block;
}
#drag_drop_area.drop_animate{
    transform: scale(0.94,0.94);
    box-shadow: 0 0 6px 2px rgba(170,220,0,1);
    background:#2e2e54;
}
              
            
!

JS

              
                //Create the audio context  
if (! window.AudioContext){
    if (! window.webkitAudioContext) {
        alert('no audiocontext found');
    }
    window.AudioContext = window.webkitAudioContext;
}
var context = new AudioContext();
var audioBuffer;
var sourceNode;
var analyser;
var javascriptNode;

function setupAudioNodes(){
    //Setup a javascript node
    javascriptNode = context.createScriptProcessor(2048, 1, 1);
    //Connect our javascript node to the audio context destination
    javascriptNode.connect(context.destination);

    //Setup an analyzer
    analyser = context.createAnalyser();
    analyser.smoothingTimeConstant = 0.6;
    analyser.fftSize = 512;
    //Create a buffer source node
    sourceNode = context.createBufferSource();
    sourceNode.connect(analyser);
    analyser.connect(javascriptNode);

    sourceNode.connect(context.destination);
}

//Retrieves, loads and plays an audio URL
function loadSound(url){
    $("#loading").show();
    var request = new XMLHttpRequest();
    request.open('GET', url, true);
    request.responseType = 'arraybuffer';

    //When loaded, decode the data and play it
    request.onload = function(){
        $("#loading").hide();

        context.decodeAudioData(request.response, function(buffer){
            playSound(buffer);
        }, onError);
    };
    request.send();
}

//Gotta log those errors
function onError(e){
    console.log(e);
}

var inkBarHeight = 358;
var inkBarSurfaces = undefined;
var inkBarEmpties = undefined;

//Animate our ink bars
function drawSpectrum(barsArray){
    for(var i = 0; i < 5; i++){
        var value = barsArray[i];
        var changeInkShape = (Math.random() * 5) > 3; //Okay-ish chance of ink surface changing shape

        //Lets lie a bit about our audio levels, to make the visualizaton look a bit more crazy
        var newBarTop = inkBarHeight - Math.floor(((value - 140) / 112) * inkBarHeight);

        //Uncomment this to get the original accurate bar levels, no lies.
        //var newBarTop = inkBarHeight - Math.floor((value / 256) * inkBarHeight);

        //Change the amount of ink in the tank!
        $(inkBarEmpties).eq(i).css("height", newBarTop + 1);
        $(inkBarSurfaces).eq(i).css("top", newBarTop);
        //Change the shape of our ink surface!
        if(changeInkShape){
            if( $("#toggle_audio").hasClass("pause") ){
                var newPosX = Math.floor(Math.random() * 1158);
                $(inkBarSurfaces).eq(i).css("background-position", "-" + newPosX + "px 0px");
            }
        }
    }
}

var splatoonURL = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/12109/splatoon_bgm_loop_small.ogg";


//Start doing stuff once the page is loaded!
$(document).ready(function(){
    //Prepare everything that uses the DOM
    inkBarSurfaces = $("#equalizer_container .ink .ink_surface");
    inkBarEmpties = $("#equalizer_container .ink .ink_empty");

    $("#toggle_audio").on("click",function(el){
        if($(el.target).hasClass("pause")){
            sourceNode.disconnect();
        }
        else{
            sourceNode.connect(analyser);
            analyser.connect(javascriptNode);
            sourceNode.connect(context.destination);
        }
        $(el.target).attr("class", $(el.target).hasClass("pause") ? "play":"pause");
    });

    //Init and load the music
    setupAudioNodes();

    //Analyze our sound node, using an analyzer (duh)!
    javascriptNode.onaudioprocess = function(){
        //var barsArray =  new Uint8Array(analyser.frequencyBinCount); //256 equalizer bars by default
        var barsArray =  new Uint8Array(5); //5 equalizer bars
        //Get the channel average
        analyser.getByteFrequencyData(barsArray);
        //Splat the audio spectrum into our ink tanks
        drawSpectrum(barsArray);
    };

    loadSound(splatoonURL);
});

var bufferStarted = false;
//Lay down the beats, looped
function playSound(buffer){
    sourceNode.buffer = buffer;
    sourceNode.loop = true;
    sourceNode.disconnect();

    if(!bufferStarted){
        sourceNode.start(0);
        bufferStarted = true;
    }

    $("#toggle_audio").attr("class", "pause");
    sourceNode.connect(analyser);
    analyser.connect(javascriptNode);
    sourceNode.connect(context.destination);
}
              
            
!
999px

Console