cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              !function () {
  function createCanvasElement (width, height, insertAfter) {
    // Creates a scaled-up canvas based on the device's
    // resolution, then displays it properly using styles
    function createHDCanvas (ratio) {
      var canvas = document.createElement('canvas');
      var ctx = canvas.getContext('2d');

      // Creates a dummy canvas to test device's pixel ratio
      ratio = (function () {
        var ctx = document.createElement('canvas').getContext('2d');
        var dpr = window.devicePixelRatio || 1;
        var bsr = ctx.webkitBackingStorePixelRatio ||
                  ctx.mozBackingStorePixelRatio ||
                  ctx.msBackingStorePixelRatio ||
                  ctx.oBackingStorePixelRatio ||
                  ctx.backingStorePixelRatio || 1;
        return dpr / bsr;
      })();

      canvas.width = width * ratio;
      canvas.height = height * ratio;
      canvas.style.width = width + 'px';
      canvas.style.height = height + 'px';
      ctx.setTransform(ratio, 0, 0, ratio, 0, 0);

      return canvas;
    }

    // Returns mouse coordinates that are
    // relative to the canvas, i.e. useful
    var relativeMouseCoords = function (event) {
      var totalOffsetX = 0;
      var totalOffsetY = 0;
      var currentElement = this;

      do {
        totalOffsetX += currentElement.offsetLeft - currentElement.scrollLeft;
        totalOffsetY += currentElement.offsetTop - currentElement.scrollTop;
        currentElement = currentElement.offsetParent;
      } while (currentElement);

      var canvasX = event.pageX - totalOffsetX;
      var canvasY = event.pageY - totalOffsetY;

      return {
        x: canvasX,
        y: canvasY
      };
    };

    var canvas = createHDCanvas();
    canvas.getCoords = relativeMouseCoords;

    if (insertAfter) insertAfter.parentNode.insertBefore(canvas, insertAfter.nextSibling);
    else document.body.appendChild(canvas);

    return canvas;
  };

  function handleKeydown (e) {
    e = e || window.event;
    if (!spacePressed && e.keyCode === 32) {
      spacePressed = true;
      ripple({
        x: windowWidth / 2,
        y: windowHeight / 2
      }, true);
    }
  }

  var ripple = (function() {
    var batch = [];

    function tick () {
      // increment radius step:
      batch.forEach(function (circle) { circle.radius += rippleSpeed; });

      // drawing step:
      ctx.fillStyle = '#00baff';
      ctx.fillRect(0, 0, windowWidth, windowHeight);

      batch.forEach(function (circle) {
        ctx.fillStyle = 'rgba(255,255,255,' + (1 - circle.radius / maxRadius) * 0.8 + ')';
        ctx.beginPath();
        ctx.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2);
        ctx.closePath();
        ctx.fill();
      });

      // remove finished animations step:
      batch = batch.filter(function (circle) {
        return circle.radius < maxRadius;
      });

      if (batch.length) {
        requestAnimationFrame(tick);
      }
    }

    return function (e, keyboard) {
      var circle;
      if (keyboard) circle = e;
      else {
        e = e || window.event;
        circle = canvas.getCoords(e);
      }
      circle.radius = 0;
      if (batch.push(circle) === 1) requestAnimationFrame(tick);
    };
  })();

  var windowHeight = window.innerHeight;
  var windowWidth = window.innerWidth;
  var maxRadius = Math.max(windowWidth, windowHeight);
  var rippleSpeed = maxRadius / 40;
  var canvas = createCanvasElement(windowWidth, windowHeight);
  var ctx = canvas.getContext('2d');
  var spacePressed = false;

  canvas.addEventListener('click', ripple, false);
  document.addEventListener('keydown', handleKeydown, false);
  document.addEventListener('keyup', function (e) {
    e = e || window.event;
    if (e.keyCode === 32) spacePressed = false;
  }, false);
}();

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console