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

              
                #visualizer
#fileTooltip
  p Drop an audio file here
  small (or click anywhere to show the open file dialog)
input#musicFile(type='file', accept='audio/*')
              
            
!

CSS

              
                body
  background: #000
  margin: 0
#visualizer canvas
  width: 100%
  height: 100%
  position: fixed
  top: 0
  left: 0

#fileTooltip
  position: fixed
  z-index: 2
  color: #FFF
  text-align: center
  width: 100%
  background: rgba(0,0,0,.7)
  padding-bottom: 1em
  top: 40vh
  transition: opacity 1s ease-in-out
  
#musicFile
  cursor: default
  position: fixed
  z-index: 10
  width: 100%
  height: 100%
  opacity: 0
              
            
!

JS

              
                ###
# Graphics 
###
w = window.innerWidth
h = window.innerHeight
baseRotation = 0
# Create a Renderer
renderer = PIXI.autoDetectRenderer w, h, { antialias: true }
center = new PIXI.Point w/2, h/2
# Append it to #visualizer
document.getElementById 'visualizer'
.appendChild renderer.view
# Create a stage
vis = new PIXI.Container()
vis.interactive = true
# Create an array of numbers (frq data)
data = (64 for [0..128])
# Create 23 graphics (to render the lines)
lines = (new PIXI.Graphics() for [0..23])
for line in lines
  vis.addChild line

animate=()->
  baseRotation += 0.0025
  # Draw 23 lines
  for i in [0..23]
    line = lines[i]
    line.clear()
    line.position = line.pivot = center
    line.lineStyle 8, 0x00CC00, 1
    line.moveTo w/2,h/2
    # Each line represents an element in the data array
    line.lineTo w/2-data[i*5]+64,h/2-data[i*5]+64
    line.alpha = 0.005*data[1*5]
    line.rotation = baseRotation + 0.2617993878*i
  renderer.render vis

# Resize the canvas when the window resizes
window.onresize = ->
  w = window.innerWidth
  h = window.innerHeight
  center = new PIXI.Point w/2, h/2
  renderer.resize w,h
  
###
# Audio 
###
context = new (window.AudioContext || window.webkitAudioContext)()
analyser = context.createAnalyser()
analyser.fftSize = 256
bufferLength = analyser.frequencyBinCount
# Create an empty audio source
source = context.createBufferSource()
analyser.connect context.destination
# Get the file element
fileElement = document.getElementById 'musicFile'
file = undefined
# Start when a file is chosen
fileElement.addEventListener 'change', ->
  reader = new FileReader()
  reader.onload = (ev)->
    # Decode and load the audio file
    context.decodeAudioData ev.target.result, (buffer)->
      try
        source.stop()
      source = context.createBufferSource()
      source.loop = true
      source.connect analyser
      document.getElementById('fileTooltip').style.opacity = 0
      source.buffer = buffer
      source.start()
      # Configure the analyser and reinitialize the data array
      data = new Uint8Array analyser.frequencyBinCount
      
  reader.readAsArrayBuffer @files[0]

### 
# Main Loop
###
update = ()->
  requestAnimationFrame update
  animate()
  if source.buffer
    analyser.getByteTimeDomainData data
  
# Start the loop
update()
              
            
!
999px

Console