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.

Quick-add: + add another resource

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.

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.

            
              <img style="position:absolute;" src="http://experiments.brandonbrule.com/valve-canvas/valve-logo.png">
            
          
!
            
              // requestAnim shim layer by Paul Irish
window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame || 
    window.webkitRequestAnimationFrame || 
    window.mozRequestAnimationFrame    || 
    window.oRequestAnimationFrame      || 
    window.msRequestAnimationFrame     || 
    function(/* function */ callback, /* DOMElement */ element){
    window.setTimeout(callback, 500);
  };
})();

var context, toggle, canvas;

// Array of Colours to go through
var myColourStringArray = [
  "rgba(243,111,33, 0.2)",
  "rgba(243,111,33, 0.6)", 
  "rgba(255, 255, 255, 0.1)"
];

// Reusable Random Function      
function rand(seed){
      return Math.floor(Math.random() * seed);
}

// Randomize array function
function randArray(array){
  var i = rand(array.length -1);
  // -1 prevents an empty array value.
  return array[i];
}


init();

function init() {
  canvas = document.createElement( 'canvas' );
  canvas.width = 495;
  canvas.height = 330;
  context = canvas.getContext( '2d' );
  document.body.appendChild( canvas );
  animate();
}

function animate() {
  requestAnimFrame( animate );
  draw();
}

function createSquare(options) {
    context.beginPath();
    context.rect(
      rand(canvas.width),
      rand(canvas.height),
      rand(canvas.width) / 100,
      rand(canvas.height) / 2
    );
    
    context.fillStyle = options.color || "rgba(" 
      + rand(255) + ","
      + rand(255) + ","
      + rand(255) + ","
      + Math.random() + 
    ")";
    
    context.fill();
    
}

    
function draw(){
    for (var i in myColourStringArray) {
      createSquare({
        color: myColourStringArray[i]
      }); 
        
    }
  
}


            
          
!
999px
Loading ..................

Console