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

            
              body {
  position: absolute;
  width: 100%;
  height: 100%;
}
canvas {
  width: 300px;
  height: 300px;
}
            
          
!
            
              // --------------------------
// Setup Canvas
// --------------------------

// canvas
var c = $('#wall');
// get canvas context so we can draw on it later
var ctx = c[0].getContext('2d');
// image(s) we will be drawing...
var wall_image_urls = [
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_01.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_02.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_03.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_04.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_05.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_06.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_07.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_08.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_09.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_10.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_11.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_12.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_13.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_14.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_15.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_16.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_17.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_18.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_19.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_20.jpg'
];

// --------------------------
// load a wall image
// --------------------------

var wall_image_data;
wall_image = new Image();
// make sure you add the onload event before the src or the image may load be fire this func is defined
wall_image.onload = function(){
  imgWidth = this.width;
  imgHeight = this.height; 
  
  // store image obj in array
  wall_image_data = {
    img: this, // image obj to be drawn by canvas
    imgWidth: imgWidth,
    imgHeight: imgHeight
  }
  
  // draw the image
  draw();  
};
wall_image.src = wall_image_urls[0];

// function draw the image
function draw() {
  // get the image/canvas ratio
  var wallHeight = c.height();
 
  // draw away...
  ctx.drawImage(wall_image_data.img, 0, 0, wall_image_data.imgWidth,wall_image_data.imgHeight);
}
            
          
!
999px
Loading ..................

Console