cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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>
<nav>
  <p>blue</p>
  <p>green</p>
  <p>orange</p>
  <p>pink</p>
</nav>
<footer>eeottati.com</footer>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Montserrat');

body {
  background: #212121;
  font-family: 'montserrat'
}

canvas {
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
}

nav {
  position: absolute;
  font-size: 20px;
  color: #999999;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  p {
    display: inline-block;
    margin: 0 10px 0 10px;
    cursor: pointer;
    
    &:nth-child(1) { color: #49FDFE; }
    &:nth-child(2) { color: #C7F202; }
    &:nth-child(3) { color: #FFAB00; }
    &:nth-child(4) { color: #FF6699; }
    
    &:hover {
      text-decoration: underline;
    }
  }
}

footer {
  position: fixed;
  color: #999999;
  font-size: 13px;
  bottom: 0px;
  right: 0px;
  margin: 15px;
  cursor: pointer;
  
  &:hover {
    color: #FFFFFF;
  }
}
            
          
!
            
              var EEO = EEO || {};

// --------------------------------
// --------------------------------

EEO.Event = function() { this._observers = []; };
EEO.Event.prototype = {

	/*---------------------------------------
    Attach the supplied observer to this Event
  ---------------------------------------*/
  attach: function(argObserver) { this._observers.push(argObserver); },

	/*---------------------------------------
    Notify all observers of this Event
  ---------------------------------------*/
  notify: function(args) {
		for(var i = 0, l = this._observers.length; i < l; i++) {
			this._observers[i](args);
		}
	}
	
};

// --------------------------------
// --------------------------------

EEO.Particle = function(argNext, argX, argY, argSX, argSY, argMovX, argMovY, argAlpha) {
  this.nxt = argNext;
	this.x = argX;
	this.y = argY;
	this.sX = argSX;
	this.sY = argSY;
	this.movX = argMovX;
	this.movY = argMovY;
	this.alpha = argAlpha;
};

// --------------------------------
// --------------------------------

EEO.ParticleController = (function(argParticle) {
  
  // Objects
  var _Particle = argParticle;
  
  // Elements
  var _canvas, _ctx;
  
  // Other vars
  var _nodeListStart, _nodeListEnd, _intWindowWidth, _intWindowHeight, _strColor;
  
  /*---------------------------------------
    Initialize ParticleController
  ---------------------------------------*/
  function init(argCanvas, argParticleCount, argUpdateInterval, argStartColor, argWindowWidth, argWindowHeight) {
    
    // Elements
    _canvas = argCanvas;
    _ctx = _canvas.getContext('2d');
    
    // Node pointers
    _nodeListStart = undefined;
    _nodeListEnd = undefined;
    
    // Initial settings
    _strColor = argStartColor;
    _intWindowWidth = argWindowWidth;
    _intWindowHeight = argWindowHeight;
    
    // Populate, and start
    _populate(argParticleCount);
    setInterval(_update, argUpdateInterval);
  }
  
  /*---------------------------------------
    Populate particles
  ---------------------------------------*/
  function _populate(argParticleCount) {
    
    for(var i = 0; i < argParticleCount; i++) {
      
      var tmpX = _rand(0, _intWindowWidth);
      var tmpY = _rand(0, _intWindowHeight);
      var angle = _rand(0, 360);
      var velocity = _rand(1, 3);
      
      var pNode = new _Particle(undefined, tmpX, tmpY, tmpX, tmpY, 0, 0, velocity * 0.1);
      
      if (_nodeListStart === undefined) _nodeListStart = pNode;
      if (_nodeListEnd === undefined) _nodeListEnd = pNode;
      
      pNode.movX = Math.cos(Math.PI / 180 * angle) * velocity;
      pNode.movY = Math.sin(Math.PI / 180 * angle) * velocity;
      
      _nodeListEnd.nxt = pNode;
      _nodeListEnd = pNode;
      
    }
    
  }
  
  /*---------------------------------------
    Update/run particles
  ---------------------------------------*/
  function _update() {
    
    _ctx.clearRect(0, 0, _intWindowWidth, _intWindowHeight);
    _ctx.fillStyle = _strColor;
    
    var node = _nodeListStart;
    while(node !== undefined) {
      
      if ((node.x < 0) || (node.x > _intWindowWidth) || (node.y < 0) || (node.y > _intWindowHeight)) {
        node.x = node.sX;
        node.y = node.sY;
      }else {
        node.x += node.movX;
        node.y += node.movY;
      }
      
      _ctx.globalAlpha = node.alpha;
      _ctx.fillRect(node.x, node.y, 2, 2);
      
      node = node.nxt;
      
    }

  }
  
  /*---------------------------------------
    Resize canvas
  ---------------------------------------*/
  function resize(argCanvasUpdate, argWindowWidth, argWindowHeight) {
    
    _canvas = argCanvasUpdate;
    _ctx = _canvas.getContext('2d');
    
    _intWindowWidth = _canvas.width = argWindowWidth;
    _intWindowHeight = _canvas.height = argWindowHeight;
    
  }
  
  /*---------------------------------------
    Update particle color
  ---------------------------------------*/
  function updateColor(argColor) {
    _strColor = argColor;
	}
  
  /*---------------------------------------
		Return random integer between argMin & argMax
	---------------------------------------*/
	function _rand(argMin, argMax) {
		return Math.round(Math.random() * (argMax - argMin) + argMin);
	}
  
  return {
    init: init,
    resize: resize,
    updateColor: updateColor
  }
})(EEO.Particle);

// --------------------------------
// --------------------------------

EEO.CanvasView = (function($, argParticleController) {
  
  // Refs
  var _particleController = argParticleController;
  
  // Elements
  var _canvas;
  
  /*---------------------------------------
    Initialize CanvasView
  ---------------------------------------*/
  function init(args) {
    
    // Elements
    _canvas = $('canvas')[0];
    
    // Initialize particle controller
    _particleController.init(
      _canvas,
      args.count,
      args.updateInterval,
      args.startColor,
      $(window).width(),
      $(window).height()
    );
    
    // Initial resize
    resize();
  }
  
  /*---------------------------------------
    Resize canvas
  ---------------------------------------*/
  function resize() {
    _particleController.resize(
      _canvas,
      $(window).width(),
      $(window).height()
    );
  }
  
  /*---------------------------------------
    Update color
  ---------------------------------------*/
  function updateColor(args) {
    _particleController.updateColor(args.color);
	}
  
  return {
    init: init,
    resize: resize,
    updateColor: updateColor
  }
})(jQuery, EEO.ParticleController);

// --------------------------------
// --------------------------------

EEO.NavView = (function($, argEvent) {
  
  // Elements
  var _nav;
  
  // Events
  var e_colorChoice = new argEvent();
  
  /*---------------------------------------
    Initialize NavView
  ---------------------------------------*/
  function init() {
    
    // Elements
    _nav = $('nav p');
    _nav.click(_navClick);
    
  }
  
  /*---------------------------------------
    Nav mouse-click
  ---------------------------------------*/
  function _navClick() {
    e_colorChoice.notify({
      color: $(this).css('color')
    });
  }
  
  return {
    init: init,
    e_colorChoice: e_colorChoice
  }
})(jQuery, EEO.Event);

// --------------------------------
// --------------------------------

EEO.FooterView = (function($) {
  
  // Elements
  var _footer;
  
  /*---------------------------------------
    Initialize FooterView
  ---------------------------------------*/
  function init() {
    
    // Elements
    _footer = $('footer');
    _footer.click(_footerClicked);
  }
  
  /*---------------------------------------
    Footer clicked
  ---------------------------------------*/
  function _footerClicked() {
    window.open("http://www.eeottati.com/");
  }
  
  return {
    init: init
  }
})(jQuery);

// --------------------------------
// --------------------------------

EEO.PenController = (function($, argCanvasView, argNavView, argFooterView) {
  
  // Views
  var _CanvasView = argCanvasView;
  var _NavView = argNavView;
  var _FooterView = argFooterView;
  
  /*---------------------------------------
    Initialize PenController
  ---------------------------------------*/
  function init(args) {
    
    // Initialize views
    _CanvasView.init({
      count:            args.canvasView.particleCount,
      updateInterval:   args.canvasView.updateInterval,
      startColor:       args.canvasView.startColor
    });
    _NavView.init();
    _FooterView.init();
    
    // Bind resize events
    $(window).resize(_CanvasView.resize);
    
    // Bind color change events
    _NavView.e_colorChoice.attach(_CanvasView.updateColor);
    
  }
  
  return {
    init: init
  }
})(jQuery, EEO.CanvasView, EEO.NavView, EEO.FooterView);

// --------------------------------
// --------------------------------

$(function() {
  EEO.PenController.init({
    canvasView: {
      particleCount:    10000,
      updateInterval:   35,
      startColor:       "#49FDFE"
    }
  });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console