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

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.

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

              
                <body>
  <div id = "tester"></div>
   <div id="animated-background">
  <canvas id="animated-background-canvas"></canvas>
     </div>
</body>
              
            
!

CSS

              
                body{
  width: 100vw;
  height: 100vh;
  box-sizing: border-box;
  padding: 5px;
  margin: 0;
  overflow: hidden;
  background-color:#321d3e; 
}

#animated-background{
  position: relative;
  width:100%;
  height:100%;
  overflow: hidden;
  /*background-color: #647a5f;*/
  /*background-color: #001233;*/
  /*background-color: #010411;*/
  background-color: #321d3e;
}

#animated-background-canvas{
  position: absolute;
  transform: translate(-50% , -50%) ;
  top: 50% ;
  left: 50% ;
}

#tester{
  color: white;
  z-index: 999;
  position: fixed;
}



              
            
!

JS

              
                //start animated background
$(function(){  
  // options 
  var squareSize = 40; // size of squares
  var amount = 220 ; // a number from 1 to 1000 : displays more or less squares
  var removeAmount = 80 ;  // amount of removing squares
  var popInterval = 60 ;
  var opacity = 1 ;
  var zone = 1 ;  // 1/n of the space. 1 takes all the canvas
  var splatter = 0 ;  // more splatter = less squares on the edges
  
  //var squareLife = 160 ; // duration of each before it disapeears
  
    // var colors = ['#6e856b', '#6a866d' ,  '#72896f', '#6d8468', '#6e8569' , '#70886e' , '#70886e' , '#6b876e'] ;
    var colors = [ '#583542' ,  '#865841', '#bc8431', '#f9b900'] ;
  // var colors = ['#F96', '#F33', '#f5d000', '#d2d002', ':#6C9', '#008e8c', '#bd4f82' ] ;
  
$(window).on('load resize' , function(event){
         
  var bkgWidth = $('#animated-background').width() ;
  var xSquares = Math.ceil(bkgWidth/squareSize) + 1 ;
  var bkgHeight = $('#animated-background').height() ;
  var ySquares = Math.ceil(bkgHeight/squareSize) + 1;
  var realWidth = squareSize * xSquares ;
   var realHeight = squareSize * ySquares ;

$('#animated-background-canvas').css({"width" : realWidth + "px" , "height" : realHeight + "px"});
  $('#animated-background-canvas').attr({"width" : realWidth + "px" , "height" : realHeight + "px"}); 
  });
 
  
  window.setInterval(function(){
    var bkgWidth = $('#animated-background').width() ;
    var xSquares = Math.ceil(bkgWidth/squareSize) + 1 ;
    var bkgHeight = $('#animated-background').height() ;
    var ySquares = Math.ceil(bkgHeight/squareSize) + 1;
    var totalSquares = xSquares * ySquares ;
    var randSquareRatio = amount / 1000;
    var randSquareCount =  Math.floor(randSquareRatio * totalSquares) ;
    var remRatio = removeAmount / 1000;
    var remCount =  Math.floor(remRatio * totalSquares) ;

    
      for(i = 0 ; i < randSquareCount ; i++){ 
         function getRandomColor() {
	         return colors[Math.floor(Math.random()*colors.length)];
	  } 
  
             
    function draw() {
    
      var zone1 = zone / (Math.pow(Math.random() , splatter )) ;
      var xAddRand = Math.floor(((Math.random() / zone1) * xSquares) + (xSquares / 2) - (xSquares / (2 * zone1))) ;
      var xAddPos = xAddRand * squareSize ;
      var yAddRand = Math.floor(((Math.random() / zone1) * ySquares) + (ySquares / 2) - (ySquares / (2 * zone1))) ;
      var yAddPos = yAddRand * squareSize ;
      var RandomColor = getRandomColor();
      var canvas = document.getElementById('animated-background-canvas');
      var ctx = canvas.getContext('2d');

   if (canvas.getContext) {


     ctx.fillStyle = RandomColor ;
               ctx.globalAlpha = opacity ;   
               ctx.fillRect(xAddPos, yAddPos, squareSize, squareSize); 

         }//if  
          
}; //draw  
        
  draw(); 
   
   
      } //for
      
      for(i = 0 ; i < remCount ; i++){ 
       
    function remove() {
      var xRemRand = Math.floor(Math.random() * xSquares) ;
      var xRemPos = xRemRand * squareSize ;
      var yRemRand = Math.floor(Math.random() * ySquares) ;
      var yRemPos = yRemRand * squareSize ;
      var canvas = document.getElementById('animated-background-canvas');
  if (canvas.getContext) {
      var ctx = canvas.getContext('2d');

         ctx.clearRect(xRemPos, yRemPos, squareSize, squareSize); 
         
         }//if
}; //remove
  remove(); 
      } //for      
    
 
 },popInterval); //setinterval

  });
              
            
!
999px

Console