function play(canvas) {
    var context = canvas.getContext('2d');
    var mover = new RandomMover({ x: canvas.width, y: canvas.height });
    var pen = new SimplePen(context, mover);
    var timer = setInterval(function() { pen.draw() }, 20);
}

function init() {
    var canvas = document.getElementById('x');
    canvas.width = window.innerWidth - 200;
    canvas.height = window.innerHeight - 200;

    play(canvas);

	// Open a snapshot of the canvas in a new window when it's clicked
    canvas.addEventListener('click', function() {
		var imgdata = canvas.toDataURL('image/png');
		var params = 'width=' + canvas.width + ',' + 
					 'height=' + canvas.height + ',' +
					 'toolbar=0,location=0,menubar=0,status=0,' +
					 'scrollbars=0,resizable=0';
		var child = window.open(imgdata, 'snapshot', params);
	}, false);
}

window.addEventListener('load', init, false);
