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

              
                #canvas.canvas
              
            
!

CSS

              
                body
  width 100vw
  height 100vh
  background #292929
  margin 0
  padding 0
  position relative
  overflow hidden

  .canvas
    width 100%
    height 100%
              
            
!

JS

              
                class Experience {
  constructor( container ) {
    console.clear()

    this.canvas = document.createElement( 'canvas' )
    container.appendChild( this.canvas )
    this.context = this.canvas.getContext( '2d' )

    const fps = 120
    this.fpsInterval = 1000 / fps
    this.then = Date.now()
    
    // Play with these values
    this.tailLength = 20
    this.lineWidth = 20
    this.speed = 0.02
    this.waveFrequency = 8
    this.waveHeight = 20

    this.oldPositions = []
    
    this.counter = 0

    this.resize()
    this.bind()
    this.loop()
  }
 
  bind() {
    window.addEventListener( 'resize', this.resize.bind( this ), false )
  }

  render() {
    const position = {
      'x': Math.sin( this.counter ) * 300 + this.center.x,
      'y': Math.sin( this.counter * this.waveFrequency ) * this.waveHeight + this.center.y
    }
    
    this.oldPositions.unshift( position )
    if( this.oldPositions.length > this.tailLength ) {
      this.oldPositions.pop()
    }
    
    this.context.beginPath()
    this.context.moveTo( position.x, position.y )

    for( let position of this.oldPositions ) {
      this.context.lineTo( position.x, position.y )
    }

    const gradient = this.context.createLinearGradient( this.oldPositions[0].x, this.oldPositions[0].y, this.oldPositions[this.oldPositions.length - 1].x, this.oldPositions[this.oldPositions.length - 1].y )
    gradient.addColorStop( 0.0, '#FFFFFF' )
    gradient.addColorStop( 1.0, '#323232' )

    this.context.lineWidth = this.lineWidth
    this.context.lineCap = 'round'
    this.context.strokeStyle = gradient
    this.context.stroke()
    this.context.closePath()
    
    this.counter += this.speed
  }

  loop() {
    this.raf = window.requestAnimationFrame( this.loop.bind( this ) )

    const now = Date.now()
    const delta = now - this.then

    if( delta > this.fpsInterval ) {
      this.context.clearRect( 0, 0, this.canvas.width, this.canvas.height )
      this.render()
      this.then = now
    }
  }

  resize() {
    this.canvas.width = window.innerWidth
    this.canvas.height = window.innerHeight
    this.center = {
      'x': this.canvas.width / 2,
      'y': this.canvas.height / 2
    }
    
    this.reset()
  }
  
  reset() {
    window.cancelAnimationFrame( this.raf )
    this.context.clearRect( 0, 0, this.canvas.width, this.canvas.height )
    this.loop()
  }
}

const container = document.getElementById( 'canvas' )
let experience = new Experience( container )
              
            
!
999px

Console