Canvas

by saidulu401

JavaScript

var canvas = null;
var ctx = null;
var img = null;



setup = function() {
	body = document.getElementsByTagName("body")[0]
	canvas = document.createElement('canvas');

	ctx = canvas.getContext('2d');
	
	canvas.width = window.innerWidth;
	canvas.height = window.innerHeight;

	body.appendChild(canvas);

	// Create a new image with:
	// a 'src' attribute of "/media/img/gamedev/ralphyrobot.png"
	// and an 'onload' attribute of onImageLoad
	// YOUR CODE HERE
	img = new Image();
	img.onload = onImageLoad;
	//img.src = "/media/img/gamedev/ralphyrobot.png"
  img.src = "http://placehold.it/350x150";
  
};

onImageLoad = function(){
	// Use the console.log function to print a statement to the browser console.
	// This will print once the image has been downloaded.
	// YOUR CODE HERE
	console.log("Img loaded");
  ctx.drawImage(img, 10, 10);
};

// We'll call your setup function in our test code, so
// don't call it in your code.
 setup();