Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


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


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.


Save Automatically?

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.


	<p><input id="audiofile" type="file"/></p>
	<p><audio id="music" controls="true" autoload loop></audio></p>
<canvas id="canvasanalyser" width="0" height="0"> </canvas>


                form {
	position: absolute;
	z-index: +1;

#canvasanalyser {
	background-color: black;
	position: absolute;
	left: 0px;
	top: 0px;
	padding: 0px;
	margin: 0px;



                'use strict'

const WIDTH = window.innerWidth;
const HEIGHT = window.innerHeight
// init canvas
var canvas = document.getElementById('canvasanalyser');
canvas.width = WIDTH;
canvas.height = HEIGHT;
var canvasCtx = canvas.getContext('2d');

// create a temp canvas we use for copying the real canvas into.
var tempCanvas = document.createElement("canvas"),
tempCtx = tempCanvas.getContext("2d");
tempCanvas.width = WIDTH;
tempCanvas.height = HEIGHT;

// init animationFrameRequest
var animationReq;

// Init Audio
var audio = document.getElementById('music');

audio.addEventListener('play', function() {
audio.addEventListener('ended', function() {
audio.addEventListener('pause', function() {

var fileSelect = document.getElementById('audiofile');
fileSelect.addEventListener('change', function() {
	audio.src = window.URL.createObjectURL(this.files[0]);

// Create audio context
var audioCtx = new AudioContext();
document.body.addEventListener('click', function() {
	// Chrome blocks Audiocontexts that are created before first user interaction.

var audioSrc = audioCtx.createMediaElementSource(audio);
var analyser = audioCtx.createAnalyser();
analyser.smoothingTimeConstant = 0;
analyser.fftSize = Math.pow(2, Math.ceil(Math.log(canvas.height)/Math.log(2))); // 32-32768

const bufferLength = analyser.frequencyBinCount;
const frequencyData = new Uint8Array(bufferLength);

var start = new Date();

function draw() {
	if (audio.paused) { return; }

	animationReq = requestAnimationFrame(draw);

	var barHeight = canvas.height/analyser.fftSize *2;

	// throttle at 50 Hz drawing (20 ms for less CPU usage, and a more smooth drawing)
	var now = new Date();
	if (now < new Date(start.getTime() + 20)) { return; }
	start = now;

	// copy the current canvas onto the temp canvas
	tempCtx.drawImage(canvas, 0, 0, WIDTH, HEIGHT);

	// iterate over the elements from the array
	for (var i = 0; i < frequencyData.length; i++) {
		var value = frequencyData[i];
		canvasCtx.fillStyle = 'rgb('+((value > 190) ? 255 : value)+', '+ ((value > 220) ? 255 : value-100) +', 0)';
		canvasCtx.fillRect(WIDTH - 1, HEIGHT - i*barHeight, 1, barHeight);
	// set translate on the canvas
	canvasCtx.translate(-1, 0);
	// draw the copied image
	canvasCtx.drawImage(tempCanvas, 0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT);
	// reset the transformation matrix
	canvasCtx.setTransform(1, 0, 0, 1, 0, 0);