cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <canvas></canvas>

<div id="Profile">
  <img src="https://s3-us-west-2.amazonaws.com/harriscarney/images/150x150.png"/>
  <span>Harris Carney</span>
</div>

<a href="http://codepen.io/HarrisCarney/pen/JGmqC" target="_blank">Click here for the updated version!</a>
            
          
!
            
              @import url(http://fonts.googleapis.com/css?family=Oswald:300);
@import url(http://fonts.googleapis.com/css?family=Abel);

body {
  margin: 0;
  overflow: hidden;
  background: #E9E9E9;
}

#Profile {
  position: absolute;
  margin: auto;
  top: 0; right: 0; bottom: 0; left: 0;
  width: 150px; height: 150px;
  border-radius: 150px;
}

#Profile:before {
  content: '';
  position: absolute;
  top: -8px; left: -8px;
  width: 162px; height: 162px;
  border-radius: 162px;
  border: 2px solid #BCBCBC;
}

#Profile:after {
  content: '';
  position: absolute;
  top: -13px; left: -13px;
  width: 172px; height: 172px;
  border-radius: 172px;
  border: 2px solid #FF9900;
}

#Profile img {
  border-radius: 150px;
}

#Profile span {
  position: absolute;
  bottom: -60px;
  display: block;
  width: 150px;
  text-align: center;
  font-family: 'Oswald';
  color: #333;
  font-size: 25px;
}

a {
  position: absolute;
  right: 0; top: 0; left: 0;
  text-align: center;
  font-family: 'Abel';
  background: #7ECEFD;
  padding: 6px;
  color: #fff;
  text-decoration: none;
  font-size: 20px;
}


            
          
!
            
              var canvas = $('canvas')[0];
var context = canvas.getContext('2d');

canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

var Dots = [];
var colors = ['#FF9900', '#424242', '#BCBCBC', '#3299BB'];
var maximum = 70;

function Initialize() {
  GenerateDots();

  Update();
}

function Dot() {
  this.active = true;

  this.diameter = Math.random() * 7;

  this.x = Math.round(Math.random() * canvas.width);
  this.y = Math.round(Math.random() * canvas.height);

  this.velocity = {
    x: (Math.random() < 0.5 ? -1 : 1) * Math.random() * 0.7,
    y: (Math.random() < 0.5 ? -1 : 1) * Math.random() * 0.7
  };

  this.alpha = 0.1;
  this.hex = colors[Math.round(Math.random() * 3)];
  this.color = HexToRGBA(this.hex, this.alpha);
}

Dot.prototype = {
  Update: function() {
    if(this.alpha < 0.8) {
      this.alpha += 0.01;
      this.color = HexToRGBA(this.hex, this.alpha);
    }

    this.x += this.velocity.x;
    this.y += this.velocity.y;

    if(this.x > canvas.width + 5 || this.x < 0 - 5 || this.y > canvas.height + 5 || this.y < 0 - 5) {
      this.active = false;
    }
  },

  Draw: function() {
    context.fillStyle = this.color;
    context.beginPath();
    context.arc(this.x, this.y, this.diameter, 0, Math.PI * 2, false);
    context.fill();
  }
}

function Update() {
  GenerateDots();

  Dots.forEach(function(Dot) {
    Dot.Update();
  });

  Dots = Dots.filter(function(Dot) {
    return Dot.active;
  });

  Render();
  requestAnimationFrame(Update);
}

function Render() {
  context.clearRect(0, 0, canvas.width, canvas.height);
  Dots.forEach(function(Dot) {
    Dot.Draw();
  });
}

function GenerateDots() {
  if(Dots.length < maximum) {
    for(var i = Dots.length; i < maximum; i++) {
      Dots.push(new Dot());
    }
  }

  return false;
}

function HexToRGBA(hex, alpha) {
  var red = parseInt((TrimHex(hex)).substring(0, 2), 16);
  var green = parseInt((TrimHex(hex)).substring(2, 4), 16);
  var blue = parseInt((TrimHex(hex)).substring(4, 6), 16);

  return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + alpha + ')';
}

function TrimHex(hex) {
  return (hex.charAt(0) == "#") ? hex.substring(1, 7) : h;
}

$(window).resize(function() {
  Dots = [];
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
});

Initialize();
            
          
!
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