Pen Settings

HTML

CSS

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

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

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.

HTML

              
                .binary
	- (0..60).each do |i|
		.num-string
.binary
	- (0..60).each do |i|
		.num-string
		
.corner-decoration

%section.converterApp
	%h1.title HTML to Audio 
	%p.disclaimer
		HTML to audio converter. Hear your <strong>websites scream in pain</strong> or <strong>sing with delight</strong>! <br /><span>(note: it breaks if html given is malformed/some other edge cases).</span>
	%textarea#text2parse.textbox
		<!DOCTYPE html>
		<html>
		<head>
		</head>
		<body>
		<h1 id="hasId">hello everyone</h1>
		<div></div>
		<div class="one"></div>
		<p class="what does this mean">this is a<br> paragraph</p>
		</body>
		</html>
	%button#playBtn.btn :&#9658;
	
.sample
	%p Pre-recorded<br />samples of<br /><span>Facebook</span><br /><span>Github</span><br /><span>Codepen</span><br />and <span>Nintendo</span><br />on <a href="https://soundcloud.com/william-anderson-421819969/sets/the-screams-of-websites" target="_blank">SoundCloud</a>
              
            
!

CSS

              
                @import 'bourbon';

$black: black;
$terminal: #00ff00;
$ice: #47D1FF;

* {
	font-family: monospace;
	letter-spacing: 1px;
}

body {
	background-color: black;
}

.sample {
	position: fixed;
	top: 0;
	right: 0;
	padding: 1em 2em;
	text-align: right;
	
	span {
		color: $ice;
	}
	
	p {
		color: white;
	}
	
	a {
		color: $terminal;
		&:hover {
			opacity: 0.5;
		}
	}
}

.converterApp {
	display: block;
	position: relative;
	top: 45vh;
	width: 650px;
	margin: 0 auto;
	@include transform(translateY(-50%));
}

.title {
	width: 100%;
	position: relative;
}

.title:before {
	content: 'HTML to Audio Converter ™';
	color: $terminal;
	font-weight: normal;
	width: 100%;
	text-align: center;
	position: absolute;
	top: 0;
	left: 0;
	@include animation(title-glitch 2.0s ease-in);
	@include animation-iteration-count(infinite);
}
	
.disclaimer {
	color: darken(white, 35%);
	width: 650px;
	box-sizing: border-box;
	margin: 0 auto 1em;
	font-size: 16px;
	line-height: 24px;
	text-align: center;
	box-sizing: border-box;
	padding: 1.5em;
	@include animation(blur-flicker 6.0s ease-in);
	@include animation-iteration-count(infinite);
	
	strong {
		font-weight: normal;
		color: $ice;
	}
	
	span {
		font-size: 12px;
		color: darken(white, 50%);
	}
}
	
.textbox {
	@include animation(console 20.0s ease-in);
	@include animation-iteration-count(infinite);
	display: block;
	box-sizing: border-box;
	width: 650px;
	height: 30vh;
	margin: 0 auto;
	color: $terminal;
	background: $black;
	padding: 1em;
	border: 1px solid white;
	box-shadow: 10px 10px 10px darken($terminal, 10%);
}
	
.btn {
		@include transform(translateX(45%) translateY(-50%));
	@include filter(blur(1px));
	display: block;
	border: 2px solid white;
	background: black;
	color: $ice;
	text-align: center;
	font-size: 2em;
	padding: 0.25em .5em;
	position: absolute;
	right: 0;
	cursor: pointer;
	outline: 0;
	
	&:hover {
		color: $terminal;
		@include filter(blur(2px));
		@include animation(shake-right 1.0s ease-in);
		@include animation-iteration-count(infinite);
	}
	
	span {
		font-size: 12px;
		position: relative;
		top: -7px;
	}
}

.binary {
	display: block;
	position: absolute;
	width: 15px * 60;
	top: 0;
	left: 0;
	background: black;
	
	&+.binary {
		left: auto;
		right: 0;
	}
}

.num-string {
	display: block;
	float: left;
	background: darken($terminal, 55%);
	height: 100vh;
	
	&:before {
		content: '0 1 1 0 1 0 0 0 1 0 1 0 0 1 0 1 0';
		color: darken($terminal, 40%);
		display: block;
		width: 15px;
		text-align: center;
		@include animation(binary 1.0s ease-in);
		@include animation-iteration-count(infinite);
	}
}

.corner-decoration {
	display: block;
	position: fixed;
	bottom: 0;
	left: 0;
	width: 20px;
	height: 20px;
	background-color: $terminal;
	opacity: 0.4;
	
	&:after {
		content: ' ';
		position: fixed;
		bottom: 0;
		left: 0;
		display: block;
		width: 100vw;
		height: 4px;
		background-color: $terminal;
	}
}

@for $i from 1 through 60 {
	.num-string:nth-child(#{$i}) {
			margin-top: random(12) * $i * -1px;
	}
}

@include keyframes(binary) {
	0% {
		content: '0 1 1 0 1 0 0 0 1 0 1 0 0 1 0 1 0';
	}
	10% {
		content: '0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 0 1';
	}
	20% {
		content: '1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 0';
	}
	30% {
		content: '0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 1';
	}
	40% {
		content: '1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 1';
	}
	50% {
		content: '0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0';
	}
	60% {
		content: '1 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0';
	}
	70% {
		content: '0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 0 0 1';
	}
	80% {
		content: '0 0 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1';
	}
	90% {
		content: '1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 0 0 1 1';
	}
}

@include keyframes(shake-right) {
	0%, 49%, 56% {
		right: -3px;
	}
	50%, 55% {
		right: 3px;
	}
}

@include keyframes(blur-flicker) {
	0%, 23%, 26% {
		@include filter(blur(0px));
	}
	20%, 25% {
		@include filter(blur(1px));
	}
	22% {
		@include filter(blur(6px));
	}
	24% {
		@include filter(blur(6px));
	}
}

@include keyframes(title-glitch) {
	0%, 50%, 61% {
		content: 'HTML to Audio Converter ™';
		@include transform(translateX(0px)); 
		@include filter(blur(1px));
	}
	51%, 60% {
		content: 'HLte r Convd ioAuerTM™ to';
		@include transform(translateX(-10px));
		@include filter(blur(5px));
	}
}

@include keyframes(console) {
	0%, .3%, .9%, 40%, 42% {
		@include transform(
			translateX(0px) translateY(0px));
		@include filter(blur(0px));
	}
	.4%, .8% {
		@include transform(
			translateX(-100px) translateY(0px));
		@include filter(blur(5px));
	}
	40.1%, 40.7% {
		@include transform(
			translateX(120px) translateY(-50px));
		@include filter(blur(5px));
	}
	40.8%, 41.9% {
		@include transform(
			translateX(40px) translateY(150px));
		@include filter(blur(5px));
	}
}

// background animation
@include keyframes(matrix) {
  0%   { background-size: 20vh 1vh; 
	       background-position: 0 0  }
  50%  { background-size: 20vh 4vh; 
				 background-position: 0 130px  }
	100% { background-size: 20vh 1vh; 
				 background-position: 0 130px  }
}
              
            
!

JS

              
                # Audio Context
audioCtx = new ((window.AudioContext or window.webkitAudioContext))
trackTiming = {'sine' : 0, 'square' : 0, 'sawtooth' : 0, 'triangle' : 0}

###
	Handles Playing Notes
###
class AudioController
 
	constructor: ->
		
	playTone: (wave, freq, start, stop, gain) ->
		if wave != 'silent'
			gainNode = audioCtx.createGain()
			gainNode.value = gain
			gainNode.connect audioCtx.destination

			tone = audioCtx.createOscillator()
			tone.connect gainNode
			tone.type = wave
			tone.frequency.value = freq
			tone.start(start)
			tone.stop(start + stop)

# Generates the specifics for a notes sound, timing and duration
###
@TODO Split into 4 tracks, each with its own timing/overlay
   maybe look at number of classes and if there is an ID?
@TODO Determin Duration of note
###

node2tone = (node, totalNodes) ->
	if node.tagName == 'parsererror'
		document.getElementById('text2parse').value = "parse error"
	wave = waveForNode node
	if wave == 'silent'
		trackTiming['sine'] += 0.25
		trackTiming['square'] += 0.25
		trackTiming['sawtooth'] += 0.25
		trackTiming['triangle'] += 0.25
	else
		#yes this is some random algorithm
		freq = Math.abs(((1500 - (Math.abs(node.childNodes.length - node.tagName.length)+ 1 ) * 400) % 1500)) + (100*(trackTiming[wave]*4) % 1500) + ((totalNodes * 10) % 300)
		gain = (node.innerHTML.length % 25) / 100
		trackTiming[wave] += 0.5
	#passes note
	[wave, freq, audioCtx.currentTime + trackTiming[wave]-0.5, trackTiming[wave] + 0.25, gain] 

waveForNode = (node) ->
	if node.id.length
		return 'square'
	else if (node.classList.length > 1)
		return 'sawtooth'
	else if (node.classList.length == 1)
		return 'sine'
	else if (node.innerHTML.length > 200)
		'triangle'
	else
		"silent"
	
# Converts a html text into value sets for notes
html2tones = (html) ->	
	tones = []
	parser = new DOMParser()
	# fixes for some common broken DOM things
	html = html.replace(/<![^>]*>/g, "")
	html = html.replace(/<meta[^>]*>/g, "")
	html = html.replace(/<link[^>]*>/g, "")
	html = html.replace(/<link[^>]*\/>/g, "")
	html = html.replace(/<br>/g, "<br />")
	DOM = parser.parseFromString html, "text/xml"
	domNodes = DOM.getElementsByTagName("*")
	i = 0
	while i < domNodes.length
		tones[i] = node2tone(domNodes[i], domNodes.length)
		i++
	tones
	
# Reads in textarea calls to parsers and plays notes
generateMusic = ->	
	trackTiming = {'sine' : 0, 'square' : 0, 'sawtooth' : 0, 'triangle' : 0}
	tones = html2tones(document.getElementById('text2parse').value)
	i = 0
	while i < tones.length
		note = tones[i]
		kit.playTone note[0], note[1], note[2], note[3], note[4]
		i++
	
	
kit = new AudioController()
playBtn = document.getElementById('playBtn')
playBtn.addEventListener("click", generateMusic, false)

###
## these articles were super useful
- https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode/setPeriodicWave
- https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBiquadFilter
- https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API
- http://stackoverflow.com/questions/20156888/what-are-the-parameters-for-createperiodicwave-in-google-chrome
- https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode
###
              
            
!
999px

Console