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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <canvas id="c"></canvas>
            
          
!

CSS

            
              * {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #222;
}

#c {
  display: block;
  margin: 100px auto;
  margin: calc(50vh - 65px) auto;
}
            
          
!

JS

            
              // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel

// MIT license

(function() {
  var lastTime = 0;
  var vendors = ['ms', 'moz', 'webkit', 'o'];
  for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
    window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
    window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  }

  if (!window.requestAnimationFrame)
    window.requestAnimationFrame = function(callback, element) {
      var currTime = new Date().getTime();
      var timeToCall = Math.max(0, 16 - (currTime - lastTime));
      var id = window.setTimeout(function() {
          callback(currTime + timeToCall);
        },
        timeToCall);
      lastTime = currTime + timeToCall;
      return id;
    };

  if (!window.cancelAnimationFrame)
    window.cancelAnimationFrame = function(id) {
      clearTimeout(id);
    };
}());
// ends requestAnimationFrame polyfill

var c = document.getElementById("c");
var bc = document.createElement("canvas");
var ctx = c.getContext("2d");
var bCtx = bc.getContext("2d");
var cw = c.width = bc.width = 750,
  cx = cw / 2;
var ch = c.height = bc.height = 130,
  cy = ch / 2;
var rad = Math.PI / 180;
var maxParticles = 60;
var speed = .015;
var text = "CODEPEN";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "120px Arial black";
ctx.lineWidth = 2;
ctx.strokeStyle = "#555";
ctx.fillStyle = "rgb(0,0,0)";

var particlesRy = new Array();

function particles() {

  this.x = Math.round(Math.random() * cw) + 1;
  this.y = Math.round(Math.random() * ch) + 1;
  this.r = randomIntFromInterval(20, 60)
  this.color = "hsl(" + (Math.round(Math.random() * 360) + 1) + ",100%,50%)";
  this.pm = Math.random() < 0.5 ? -1 : 1; //plus or minus
  this.drift = this.pm * speed;
  this.fall = this.pm * speed;
}

function createParticles() {
  var l = particlesRy.length
  particlesRy[l] = new particles();
  bCtx.fillStyle = particlesRy[l].color;
  bCtx.beginPath();
  bCtx.arc(particlesRy[l].x, particlesRy[l].y, particlesRy[l].r, 0, 2 * Math.PI);
  bCtx.fill();
}

function updateParticles() {
  bCtx.clearRect(0, 0, cw, ch);
  for (var j = 0; j < particlesRy.length; j++) {
    if (particlesRy[j].x >= cw || particlesRy[j].x <= 0) {
      particlesRy[j].drift = -1 * particlesRy[j].drift;
    }
    if (particlesRy[j].y >= ch || particlesRy[j].y <= 0) {
      particlesRy[j].fall = -1 * particlesRy[j].fall;
    }
    particlesRy[j].y += particlesRy[j].fall;
    particlesRy[j].x += particlesRy[j].drift;

    bCtx.fillStyle = particlesRy[j].color;
    bCtx.beginPath();
    bCtx.arc(particlesRy[j].x, particlesRy[j].y, particlesRy[j].r, 0, 2 * Math.PI);
    bCtx.fill();
  }

}

window.addEventListener("load", function() {

  for (var i = 0; i < maxParticles; i++) {
    createParticles();
    bCtx.globalCompositeOperation = "xor";
  }

  drawText();

  requestId = window.requestAnimationFrame(Draw);

}, false)

function Draw() {
  for (var i = 0; i < maxParticles; i++) {
    updateParticles();
    bCtx.globalCompositeOperation = "xor";
  }

  drawText();

  requestId = window.requestAnimationFrame(Draw);
}

function drawText() {
  ctx.beginPath();

  ctx.fillText(text, cw / 2, ch / 2);
  ctx.strokeText(text, cw / 2, ch / 2);

  ctx.globalCompositeOperation = "source-atop";

  var img = bc;
  ctx.drawImage(img, 0, 0);
}

function randomIntFromInterval(mn, mx) {
  return ~~(Math.random() * (mx - mn + 1) + mn);
}
            
          
!
999px

Console