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

              
                
              
            
!

CSS

              
                body
  overflow: hidden
              
            
!

JS

              
                let	screenWidth = window.innerWidth;
let screenHeight = window.innerHeight;
let screenMin = (screenWidth < screenHeight) ? screenWidth : screenHeight;

const options = {
	background: '#fff',
  predraw: 200,
  color: '#000',
  count: screenWidth * screenHeight * 0.00005,
};
const prettyHues = [2, 10, 17, 37, 40, 63, 67, 72, 74, 148, 152, 156, 160, 170, 175, 189, 194, 260, 270, 280, 288, 302, 320, 330, 340, 350];

var canvas,
		c;
var dots = [];

function setup() {
  frameRate = 30;
  setupCanvas();
	c.fillStyle = options.background;
	c.strokeStyle = options.color;
  c.fillRect(-screenWidth/2, -screenHeight/2, screenWidth, screenHeight);
  makeDots(options.count);
}

function makeDots(count) {
  for (var i = 0; i < count; i++) {
    var x = randomInteger(-screenWidth*0.5,screenWidth*0.5);
    var y = randomInteger(-screenHeight*0.5,screenHeight*0.5);
    
    const dot = new Dot(x, y, i);
    
    let tempPredraw = options.predraw;
    while (tempPredraw > 0) {
      dot.update(canvas);
      dot.draw(c);
      tempPredraw--;
    }
    
    dots.push(dot);
  }
  
}

function draw() {
  for (var i = 0; i < dots.length; i++) {
    var dot = dots[i];
    dot.update(canvas);
    dot.draw(c);
  }
}

function setupCanvas() {
  canvas = document.createElement('canvas');
  c = canvas.getContext('2d');
  canvas.width = screenWidth;
  canvas.height = screenHeight;
  document.body.appendChild(canvas);
  c.translate(screenWidth/2, screenHeight/2);
}


Dot = function(x, y, index) {

  var hue = (prettyHues[randomInteger(0, prettyHues.length-1)]-20)%360;
  var sat = randomInteger(80, 100);
  var bri = randomInteger(65, 75);
  var speed = randomInteger(2, 5);

  var size = this.size = randomInteger(25, 50);
	var pos = this.pos = new Vector2(x,y);
	var vel = this.vel = new Vector2(speed,0);
	var ang = this.ang = 180-pos.angle();
  var rot = this.rot = random(1, 4);
	var dir = this.dir = randomInteger(0,1);

	vel.rotate(ang);
  
  this.color = hsl(hue, sat, bri);
  this.shadow = hsl((hue+40)%360, sat, bri);

  this.update = function(canvas) {

		// randomly change clockwiseness
		if (randomInteger(0,100) == 0) {
			dir = (dir == 1) ? 0 : 1;
		}

		// rotate
		if (dir) {
			vel.rotate(this.rot);
		} else {
			vel.rotate(-this.rot);
		}
		// add velocity to position
		pos.plusEq(vel);
  };

  this.draw = function(c) {
    c.save();
    
    c.fillStyle = this.shadow;
		c.beginPath();
      c.arc(pos.x,pos.y+5,this.size,0,Math.PI*2,true);
		c.fill();
    
    c.fillStyle = this.color;
		c.beginPath();
      c.arc(pos.x,pos.y,this.size,0,Math.PI*2,true);
		c.fill();

    c.restore();
  };

};





// IGNORE FROM HERE
//=====================================


var lastUpdate = Date.now();

function cjsloop() {

	var now = Date.now();
	var elapsedMils = now - lastUpdate;


	if((typeof window.draw == 'function') && (elapsedMils>=(1000/window.frameRate))) {
		window.draw();

		lastUpdate = now - elapsedMils % (1000/window.frameRate );
	}

	requestAnimationFrame(cjsloop);

};


// requestAnimationFrame
// 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

(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);
      };
}());


window.addEventListener('load',init);

function init() {
	if(typeof window.setup == 'function') window.setup();
	cjsloop();
}

              
            
!
999px

Console